IOrganizationService.RetrieveMultiple Method
Retrieves a collection of records. Namespace: Microsoft.Xrm.Sdk
Assembly: Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk)
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); }
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); }
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. To learn which attributes are valid for this operation, view the “EntityName Entity Metadata” topic.
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 |
Development Platforms
Windows Server 2008Target Platforms
Windows Server 2008, Windows 7 (All Versions), Windows Vista (All Versions)Reference
IOrganizationService InterfaceIOrganizationService Members
Microsoft.Xrm.Sdk Namespace
RetrieveMultipleRequest
RetrieveMultipleResponse
Retrieve Multiple
Other Resources
Creating Queries to Retrieve DataHow 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.
© 2011 Microsoft Corporation. All rights reserved.