Export (0) Print
Expand All

RetrieveMultiple

CRM 1.2
banner art

Retrieves a collection of entity instances based on the specified query criteria.

Syntax

[Visual Basic]
Public Function RetrieveMultiple(
  ByVal query As QueryBase
) As BusinessEntityCollection
[C#]
public BusinessEntityCollection RetrieveMultiple(
  QueryBase  query
);
[JScript]
public function RetrieveMultiple(
  query : QueryBase
) : BusinessEntityCollection;

Parameters

queryExpression

Specifies either a QueryExpression or a QueryByAttribute object derived from the QueryBase class. This is the query to be executed for an entity. The QueryExpression or QueryByAttribute object contains the type information for the entity.

Return Value

Returns a BusinessEntityCollection that is a collection of entities of the type specified in the query parameter. The collection contains the first set (approximately 50) of results for the query. To retrieve a subsequent "page" of results, copy the value from the returned BusinessEntityCollection.PagingCookie, to the field PagingInfo.PagingCookie in the queryExpression parameter.

Remarks

Use this method to retrieve one or more entity instances based on criteria specifed in the QueryExpression.

To perform this action, the caller must have the Read privilege to the entity type being retrieved and access rights on the entity instances retrieved.

This method replaces a number of existing Microsoft CRM V1.X Retrieve methods. Any Retrieve method that passes a property of the calling entity in the method signature is deprecated. Instead, the property that used to be passed in the signature is now passed as criteria in the queryExpression object.

Deprecated methods include: RetrieveByOrganization, RetrieveByPrincipal, BulkRetrieve, RetrieveByState, RetrieveBySubject, RetrieveByTerritory, RetrieveByType, RetrieveByUser, RetrieveByUserAndYear, RetrieveChildBusinesses, and RetrieveByParent. For more information, see Mapping from Version 1.2.

The ColumnSet specified within the QueryExpression can only include the objects of the type of the calling entity. For more information, see Using ColumnSet.

Example

The following code example shows how to use the RetrieveMultiple method.

[C#]
// Set up the CRM Service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the ColumnSet that indicates the fields to be retrieved.
ColumnSet cols = new ColumnSet();

// Set the properties of the ColumnSet.
cols.Attributes = new string [] {"fullname", "contactid"};

// Create the ConditionExpression.
ConditionExpression condition = new ConditionExpression();

// Set the condition for the retrieval to be when the city in the contact's address is Sammamish.
condition.AttributeName = "address1_city";
condition.Operator = ConditionOperator.Like;
condition.Values = new string [] {"Sammamish"};

// Create the FilterExpression.
FilterExpression filter = new FilterExpression();

// Set the properties of the filter.
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition};

// Create the QueryExpression object.
QueryExpression query = new QueryExpression();

// Set the properties of the QueryExpression object.
query.EntityName = EntityName.contact.ToString();
query.ColumnSet = cols;
query.Criteria = filter;
      
// Retrieve the contacts.
BusinessEntityCollection contacts = service.RetrieveMultiple(query);
[Visual Basic .NET]
' Set up the CRM Service.
Dim service As New CrmService()
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Create the ColumnSet that indicates the fields to be retrieved.
Dim cols As New ColumnSet()

' Set the properties of the ColumnSet.
cols.Attributes = New String() {"fullname", "contactid"}

' Create the ConditionExpression.
Dim condition As New ConditionExpression()

' Set the condition for the retrieval to be when the city in the contact's address is Sammamish.
condition.AttributeName = "address1_city"
condition.Operator = ConditionOperator.Like
condition.Values = New String() {"Sammamish"}

' Create the FilterExpression.
Dim filter As New FilterExpression()

' Set the properties of the filter.
filter.FilterOperator = LogicalOperator.And
filter.Conditions = New ConditionExpression() {condition}

' Create the QueryExpression object.
Dim query As New QueryExpression()

' Set the properties of the QueryExpression Object.
query.EntityName = EntityName.contact.ToString()
query.ColumnSet = cols
query.Criteria = filter

' Retrieve the contacts.
Dim contacts As BusinessEntityCollection = service.RetrieveMultiple(query)

Related Topics

Building Queries

CrmService Class

RetrieveMultiple Message


© 2007 Microsoft Corporation. All rights reserved.


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft