IOrganizationService.RetrieveMultiple Method
Applies To: Microsoft Dynamics CRM 2013, Microsoft Dynamics CRM Online
Retrieves a collection of records.
Namespace: Microsoft.Xrm.Sdk
Assembly: Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)
Syntax
'Declaration
<OperationContractAttribute> _
<FaultContractAttribute(GetType(OrganizationServiceFault))> _
Function RetrieveMultiple ( _
query As QueryBase _
) As EntityCollection
[OperationContractAttribute]
[FaultContractAttribute(typeof(OrganizationServiceFault))]
EntityCollection RetrieveMultiple (
QueryBase query
)
Parameters
- query
Type: QueryBase. A query that determines the set of records to retrieve.
Return Value
Type: EntityCollection
The collection of entities returned from the query.
Example
The following example shows how to use the RetrieveMultiple method. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface. You can find the complete sample in the sample code package in the folder SampleCode\CS\BusinessDataModel\BusinessManagement\RetrieveOpportunity.cs
.
// Retrieve Opportunity record.
Opportunity checkOpportunity = (Opportunity)_serviceProxy.Retrieve(
Opportunity.EntityLogicalName,
_opportunityId,
new ColumnSet("name"));
Console.WriteLine("Retrieved {0}", checkOpportunity.Name);
// Retrieve the related opportunity products
QueryExpression opportunityProductsQuery = new QueryExpression
{
EntityName = OpportunityProduct.EntityLogicalName,
ColumnSet = new ColumnSet("opportunityproductid", "volumediscountamount"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "opportunityid",
Operator = ConditionOperator.Equal,
Values = { _opportunityId }
}
}
}
};
DataCollection<Entity> opportunityProducts = _serviceProxy.RetrieveMultiple(
opportunityProductsQuery).Entities;
foreach (Entity entity in opportunityProducts)
{
OpportunityProduct opportunityProduct = (OpportunityProduct)entity;
Console.WriteLine("Retrieved Opportunity Product {0}",
opportunityProduct.OpportunityProductId.Value);
}
' Retrieve Opportunity record.
Dim checkOpportunity As Opportunity = CType(_serviceProxy.Retrieve(Opportunity.EntityLogicalName, _
_opportunityId, New ColumnSet("name")), Opportunity)
Console.WriteLine("Retrieved {0}", checkOpportunity.Name)
' Retrieve the related opportunity products
Dim opportunityProductsQuery As QueryExpression = New QueryExpression With _
{.EntityName = OpportunityProduct.EntityLogicalName, _
.ColumnSet = New ColumnSet("opportunityproductid", "volumediscountamount")}
opportunityProductsQuery.Criteria = New FilterExpression()
opportunityProductsQuery.Criteria.AddCondition("opportunityid", ConditionOperator.Equal, _opportunityId)
Dim opportunityProducts As DataCollection(Of Entity) = _serviceProxy.RetrieveMultiple(opportunityProductsQuery).Entities
For Each entity As Entity In opportunityProducts
Dim opportunityProduct As OpportunityProduct = CType(entity, OpportunityProduct)
Console.WriteLine("Retrieved Opportunity Product {0}", opportunityProduct.OpportunityProductId.Value)
Next entity
The following example shows how to use the RetrieveMultiple method. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface. You can find the complete sample in the sample code package in the folder SampleCode\CS\BusinessDataModel\Templates\GetEmailTemplateAttachments.cs
.
//Create a query to retrieve attachments.
QueryExpression query = new QueryExpression
{
EntityName = ActivityMimeAttachment.EntityLogicalName,
ColumnSet = new ColumnSet("filename"),
//Define the conditions for each attachment.
Criteria =
{
FilterOperator = LogicalOperator.And,
Conditions =
{
//The ObjectTypeCode must be specified, or else the query
//defaults to "email" instead of "template".
new ConditionExpression
{
AttributeName = "objecttypecode",
Operator = ConditionOperator.Equal,
Values = {Template.EntityTypeCode}
},
//Specify which template we need.
new ConditionExpression
{
AttributeName = "objectid",
Operator = ConditionOperator.Equal,
Values = {_emailTemplateId}
}
}
}
};
//Write out the filename of each attachment retrieved.
foreach (ActivityMimeAttachment attachment in _serviceProxy.RetrieveMultiple(query).Entities)
{
Console.WriteLine("Retrieved attachment {0}", attachment.FileName);
}
'Create a query to retrieve attachments.
Dim query As QueryExpression = New QueryExpression With { _
.EntityName = ActivityMimeAttachment.EntityLogicalName, .ColumnSet = New ColumnSet("filename")}
query.Criteria = New FilterExpression()
query.Criteria.AddCondition("objecttypecode", ConditionOperator.Equal, {Template.EntityTypeCode})
query.Criteria.AddCondition("objectid", ConditionOperator.Equal, {_emailTemplateId})
query.Criteria.FilterOperator = LogicalOperator.And
'Define the conditions for each attachment.
'The ObjectTypeCode must be specified, or else the query
'defaults to "email" instead of "template".
'Specify which template we need.
'Write out the filename of each attachment retrieved.
For Each attachment As ActivityMimeAttachment In _serviceProxy.RetrieveMultiple(query).Entities
Console.WriteLine("Retrieved attachment {0}", attachment.FileName)
Next attachment
Remarks
Message Availability
This message works regardless whether the caller is connected to the server or offline.
Not all entity types support this message offline. See Supported Entities later in this topic.
Privileges and Access Rights
To perform this action, the caller must have privileges on the entity that is specified in the entityName parameter. For a list of the required privileges, see RetrieveMultiple Privileges. This method only returns the records for which the calling user has access rights.
Notes for Callers
The collection of returned records contains the values for the properties that are specified in the ColumnSet parameter for which the calling user has access rights. Any other property values are not returned.
Pass null for the columnSet parameter to retrieve only the primary key. If the columnSet includes attributes that are not valid for retrieval, they are ignored. This is where IsValidForRead is false. You can find this information in the metadata for your organization. See the preceding metadata browser information.
You can use this method to retrieve records of an entity that supports the RetrieveMultiple message, including records from custom entities.
For more information about the exceptions that can be thrown when this method is called, see Handle Exceptions in Your Code.
Supported Entities
The following table shows the default entities that support this message. For the listed entities of this message, the Availability column shows Server if the caller must be connected to the server and shows Both if the caller can be either connected to, or disconnected from, the server.
Entity | Aavailability |
---|---|
account |
Both |
accountleads |
Both |
activitymimeattachment |
Both |
activityparty |
Both |
activitypointer |
Both |
annotation |
Both |
annualfiscalcalendar |
Both |
appointment |
Both |
asyncoperation |
Both |
attributemap |
Server |
audit |
Server |
bulkdeletefailure |
Both |
bulkdeleteoperation |
Both |
bulkoperation |
Both |
bulkoperationlog |
Both |
businessunit |
Both |
businessunitnewsarticle |
Both |
calendar |
Both |
campaign |
Both |
campaignactivity |
Both |
campaignactivityitem |
Both |
campaignitem |
Both |
campaignresponse |
Both |
columnmapping |
Both |
competitor |
Both |
competitorproduct |
Both |
competitorsalesliterature |
Both |
connection |
Both |
connectionrole |
Both |
connectionroleassociation |
Both |
connectionroleobjecttypecode |
Both |
constraintbasedgroup |
Both |
contact |
Both |
contactinvoices |
Both |
contactleads |
Both |
contactorders |
Both |
contactquotes |
Both |
contract |
Both |
contractdetail |
Both |
contracttemplate |
Both |
customeraddress |
Both |
customeropportunityrole |
Both |
customerrelationship |
Both |
dependency |
Server |
discount |
Both |
discounttype |
Both |
displaystring |
Both |
duplicaterecord |
Server |
duplicaterule |
Server |
duplicaterulecondition |
Both |
Both |
|
entitymap |
Server |
equipment |
Both |
fax |
Both |
fieldpermission |
Server |
fieldsecurityprofile |
Server |
fixedmonthlyfiscalcalendar |
Both |
goal |
Both |
goalrollupquery |
Both |
import |
Both |
importentitymapping |
Both |
importfile |
Both |
importjob |
Both |
importlog |
Both |
importmap |
Both |
incident |
Both |
incidentresolution |
Both |
invaliddependency |
Server |
invoice |
Both |
invoicedetail |
Both |
isvconfig |
Both |
kbarticle |
Both |
kbarticlecomment |
Both |
kbarticletemplate |
Both |
lead |
Both |
leadaddress |
Both |
leadcompetitors |
Both |
leadproduct |
Both |
letter |
Both |
license |
Both |
list |
Both |
listmember |
Both |
lookupmapping |
Both |
mailmergetemplate |
Both |
metric |
Both |
monthlyfiscalcalendar |
Both |
msdyn_postalbum |
Server |
msdyn_postconfig |
Server |
msdyn_postruleconfig |
Server |
opportunity |
Both |
opportunityclose |
Both |
opportunitycompetitors |
Both |
opportunityproduct |
Both |
orderclose |
Both |
organization |
Both |
organizationui |
Both |
ownermapping |
Both |
phonecall |
Both |
picklistmapping |
Both |
pluginassembly |
Both |
plugintype |
Both |
plugintypestatistic |
Server |
post |
Server |
postcomment |
Server |
postfollow |
Server |
postlike |
Server |
pricelevel |
Both |
principalobjectattributeaccess |
Both |
privilege |
Both |
processsession |
Both |
product |
Both |
productassociation |
Both |
productpricelevel |
Both |
productsalesliterature |
Both |
productsubstitute |
Both |
publisher |
Both |
publisheraddress |
Server |
quarterlyfiscalcalendar |
Both |
queue |
Both |
queueitem |
Both |
quote |
Both |
quoteclose |
Both |
quotedetail |
Both |
recurrencerule |
Both |
recurringappointmentmaster |
Both |
relationshiprole |
Both |
relationshiprolemap |
Both |
report |
Both |
reportcategory |
Both |
reportentity |
Both |
reportlink |
Both |
reportvisibility |
Both |
resource |
Both |
resourcegroup |
Both |
resourcespec |
Both |
role |
Both |
roleprivileges |
Both |
rollupfield |
Both |
salesliterature |
Both |
salesliteratureitem |
Both |
salesorder |
Both |
salesorderdetail |
Both |
savedquery |
Both |
savedqueryvisualization |
Both |
sdkmessage |
Both |
sdkmessagefilter |
Both |
sdkmessagepair |
Both |
sdkmessageprocessingstep |
Both |
sdkmessageprocessingstepimage |
Both |
sdkmessageprocessingstepsecureconfig |
Server |
sdkmessagerequest |
Both |
sdkmessagerequestfield |
Both |
sdkmessageresponse |
Both |
sdkmessageresponsefield |
Both |
semiannualfiscalcalendar |
Both |
service |
Both |
serviceappointment |
Both |
servicecontractcontacts |
Both |
serviceendpoint |
Server |
sharepointdocumentlocation |
Server |
sharepointsite |
Server |
site |
Both |
sitemap |
Both |
solution |
Both |
solutioncomponent |
Both |
subject |
Both |
systemform |
Both |
systemuser |
Both |
systemuserlicenses |
Both |
systemuserprofiles |
Server |
systemuserroles |
Both |
task |
Both |
team |
Both |
teammembership |
Both |
teamprofiles |
Server |
teamroles |
Both |
template |
Both |
territory |
Both |
timezonedefinition |
Both |
timezonelocalizedname |
Both |
timezonerule |
Both |
transactioncurrency |
Both |
transformationmapping |
Both |
transformationparametermapping |
Both |
uom |
Both |
uomschedule |
Both |
userentityinstancedata |
Both |
userentityuisettings |
Both |
userform |
Both |
userquery |
Both |
userqueryvisualization |
Both |
usersettings |
Both |
webresource |
Both |
workflow |
Server |
workflowdependency |
Server |
workflowlog |
Server |
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Development Platforms
Windows Server 2008, Windows Server 2012, Windows 7 (All Versions), Windows 8 (All Versions)
Target Platforms
Windows Server 2008, ,Windows Server 2012, ,Windows 7 (All Versions),
Change History
See Also
Reference
IOrganizationService Interface
IOrganizationService Members
Microsoft.Xrm.Sdk Namespace
RetrieveMultipleRequest
RetrieveMultipleResponse
Retrieve Multiple
Other Resources
Creating Queries to Retrieve Data
How Field Security Can Be Used to Control Access to Field Values In Microsoft Dynamics CRM
Handle Exceptions in Your Code
Troubleshooting and Error Handling
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.