IOrganizationService.RetrieveMultiple Method (QueryBase)

 

Applies To: Dynamics CRM 2015

Retrieves a collection of records.

Namespace:   Microsoft.Xrm.Sdk
Assembly:  Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)

Syntax

[FaultContractAttribute(typeof(OrganizationServiceFault))]
[OperationContractAttribute]
EntityCollection RetrieveMultiple(
    QueryBase query
)
[FaultContractAttribute((OrganizationServiceFault^::typeid))]
[OperationContractAttribute]
EntityCollection^ RetrieveMultiple(
    QueryBase^ query
)
[<FaultContractAttribute(typeof(OrganizationServiceFault))>]
[<OperationContractAttribute>]
abstract RetrieveMultiple : 
        query:QueryBase -> EntityCollection
<FaultContractAttribute(GetType(OrganizationServiceFault))>
<OperationContractAttribute>
Function RetrieveMultiple (
    query As QueryBase
) As EntityCollection

Parameters

Return Value

Type: Microsoft.Xrm.Sdk.EntityCollection

Type: EntityCollection
The collection of entities returned from the query.

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 message 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

Availability

Account

2 (Both)

AccountLeads

2 (Both)

ActivityMimeAttachment

2 (Both)

ActivityParty

2 (Both)

ActivityPointer

2 (Both)

Annotation

2 (Both)

AnnualFiscalCalendar

2 (Both)

Appointment

2 (Both)

AsyncOperation

2 (Both)

AttributeMap

2 (Both)

Audit

2 (Both)

BulkDeleteFailure

2 (Both)

BulkDeleteOperation

2 (Both)

BulkOperation

2 (Both)

BulkOperationLog

2 (Both)

BusinessUnit

2 (Both)

BusinessUnitNewsArticle

2 (Both)

Calendar

2 (Both)

Campaign

2 (Both)

CampaignActivity

2 (Both)

CampaignActivityItem

2 (Both)

CampaignItem

2 (Both)

CampaignResponse

2 (Both)

ColumnMapping

2 (Both)

Competitor

2 (Both)

CompetitorProduct

2 (Both)

CompetitorSalesLiterature

2 (Both)

Connection

2 (Both)

ConnectionRole

2 (Both)

ConnectionRoleAssociation

2 (Both)

ConnectionRoleObjectTypeCode

2 (Both)

ConstraintBasedGroup

2 (Both)

Contact

2 (Both)

ContactInvoices

2 (Both)

ContactLeads

2 (Both)

ContactOrders

2 (Both)

ContactQuotes

2 (Both)

Contract

2 (Both)

ContractDetail

2 (Both)

ContractTemplate

2 (Both)

ConvertRule

2 (Both)

ConvertRuleItem

2 (Both)

CustomerAddress

2 (Both)

CustomerOpportunityRole

2 (Both)

CustomerRelationship

2 (Both)

Dependency

2 (Both)

Discount

2 (Both)

DiscountType

2 (Both)

DisplayString

2 (Both)

DuplicateRecord

2 (Both)

DuplicateRule

2 (Both)

DuplicateRuleCondition

2 (Both)

DynamicProperty

2 (Both)

DynamicPropertyAssociation

2 (Both)

DynamicPropertyInstance

2 (Both)

DynamicPropertyOptionSetItem

2 (Both)

Email

2 (Both)

EmailServerProfile

2 (Both)

Entitlement

2 (Both)

EntitlementChannel

2 (Both)

EntitlementContacts

2 (Both)

EntitlementProducts

2 (Both)

EntitlementTemplate

2 (Both)

EntitlementTemplateChannel

2 (Both)

EntitlementTemplateProducts

2 (Both)

EntityMap

2 (Both)

Equipment

2 (Both)

ExchangeSyncIdMapping

2 (Both)

Fax

2 (Both)

FieldPermission

2 (Both)

FieldSecurityProfile

2 (Both)

FixedMonthlyFiscalCalendar

2 (Both)

Goal

2 (Both)

GoalRollupQuery

2 (Both)

HierarchyRule

2 (Both)

HierarchySecurityConfiguration

2 (Both)

Import

2 (Both)

ImportEntityMapping

2 (Both)

ImportFile

2 (Both)

ImportJob

2 (Both)

ImportLog

2 (Both)

ImportMap

2 (Both)

Incident

2 (Both)

IncidentResolution

2 (Both)

InvalidDependency

2 (Both)

Invoice

2 (Both)

InvoiceDetail

2 (Both)

IsvConfig

2 (Both)

KbArticle

2 (Both)

KbArticleComment

2 (Both)

KbArticleTemplate

2 (Both)

Lead

2 (Both)

LeadAddress

2 (Both)

LeadCompetitors

2 (Both)

LeadProduct

2 (Both)

Letter

2 (Both)

License

2 (Both)

List

2 (Both)

ListMember

2 (Both)

LookUpMapping

2 (Both)

Mailbox

2 (Both)

MailMergeTemplate

2 (Both)

Metric

2 (Both)

MonthlyFiscalCalendar

2 (Both)

msdyn_PostAlbum

2 (Both)

msdyn_PostConfig

2 (Both)

msdyn_PostRuleConfig

2 (Both)

msdyn_wallsavedquery

2 (Both)

msdyn_wallsavedqueryusersettings

2 (Both)

Opportunity

2 (Both)

OpportunityClose

2 (Both)

OpportunityCompetitors

2 (Both)

OpportunityProduct

2 (Both)

OrderClose

2 (Both)

Organization

2 (Both)

OrganizationUI

2 (Both)

OwnerMapping

2 (Both)

PhoneCall

2 (Both)

PickListMapping

2 (Both)

PluginAssembly

2 (Both)

PluginType

2 (Both)

PluginTypeStatistic

2 (Both)

Position

2 (Both)

Post

2 (Both)

PostComment

2 (Both)

PostFollow

2 (Both)

PostLike

2 (Both)

PriceLevel

2 (Both)

PrincipalObjectAttributeAccess

2 (Both)

Privilege

2 (Both)

ProcessSession

2 (Both)

ProcessStage

2 (Both)

ProcessTrigger

2 (Both)

Product

2 (Both)

ProductAssociation

2 (Both)

ProductPriceLevel

2 (Both)

ProductSalesLiterature

2 (Both)

ProductSubstitute

2 (Both)

Publisher

2 (Both)

PublisherAddress

2 (Both)

QuarterlyFiscalCalendar

2 (Both)

Queue

2 (Both)

QueueItem

2 (Both)

QueueMembership

2 (Both)

Quote

2 (Both)

QuoteClose

2 (Both)

QuoteDetail

2 (Both)

RecurrenceRule

2 (Both)

RecurringAppointmentMaster

2 (Both)

RelationshipRole

2 (Both)

RelationshipRoleMap

2 (Both)

Report

2 (Both)

ReportCategory

2 (Both)

ReportEntity

2 (Both)

ReportLink

2 (Both)

ReportVisibility

2 (Both)

Resource

2 (Both)

ResourceGroup

2 (Both)

ResourceSpec

2 (Both)

Role

2 (Both)

RolePrivileges

2 (Both)

RollupField

2 (Both)

RoutingRule

2 (Both)

RoutingRuleItem

2 (Both)

SalesLiterature

2 (Both)

SalesLiteratureItem

2 (Both)

SalesOrder

2 (Both)

SalesOrderDetail

2 (Both)

SavedQuery

2 (Both)

SavedQueryVisualization

2 (Both)

SdkMessage

2 (Both)

SdkMessageFilter

2 (Both)

SdkMessagePair

2 (Both)

SdkMessageProcessingStep

2 (Both)

SdkMessageProcessingStepImage

2 (Both)

SdkMessageProcessingStepSecureConfig

2 (Both)

SdkMessageRequest

2 (Both)

SdkMessageRequestField

2 (Both)

SdkMessageResponse

2 (Both)

SdkMessageResponseField

2 (Both)

SemiAnnualFiscalCalendar

2 (Both)

Service

2 (Both)

ServiceAppointment

2 (Both)

ServiceContractContacts

2 (Both)

ServiceEndpoint

2 (Both)

SharePointData

2 (Both)

SharePointDocument

2 (Both)

SharePointDocumentLocation

2 (Both)

SharePointSite

2 (Both)

Site

2 (Both)

SiteMap

2 (Both)

SLA

2 (Both)

SLAItem

2 (Both)

SLAKPIInstance

2 (Both)

SocialActivity

2 (Both)

SocialInsightsConfiguration

2 (Both)

SocialProfile

2 (Both)

Solution

2 (Both)

SolutionComponent

2 (Both)

Subject

2 (Both)

SubscriptionTrackingDeletedObject

2 (Both)

SystemForm

2 (Both)

SystemUser

2 (Both)

SystemUserLicenses

2 (Both)

SystemUserProfiles

2 (Both)

SystemUserRoles

2 (Both)

Task

2 (Both)

Team

2 (Both)

TeamMembership

2 (Both)

TeamProfiles

2 (Both)

TeamRoles

2 (Both)

TeamTemplate

2 (Both)

Template

2 (Both)

Territory

2 (Both)

TimeZoneDefinition

2 (Both)

TimeZoneLocalizedName

2 (Both)

TimeZoneRule

2 (Both)

TraceLog

2 (Both)

TransactionCurrency

2 (Both)

TransformationMapping

2 (Both)

TransformationParameterMapping

2 (Both)

UoM

2 (Both)

UoMSchedule

2 (Both)

UserEntityInstanceData

2 (Both)

UserEntityUISettings

2 (Both)

UserForm

2 (Both)

UserQuery

2 (Both)

UserQueryVisualization

2 (Both)

UserSettings

2 (Both)

WebResource

2 (Both)

Workflow

2 (Both)

WorkflowDependency

2 (Both)

WorkflowLog

2 (Both)

Examples

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

See Also

RetrieveMultipleRequest
RetrieveMultipleResponse
IOrganizationService Interface
Microsoft.Xrm.Sdk Namespace
Retrieve data with queries
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
Retrieve multiple

Return to top

© 2016 Microsoft. All rights reserved. Copyright