RetrieveMultiple Message
Retrieves a collection of business entities of a specified type based on query criteria.
The relevant classes are specified in the following table.
Type | Class |
Request | RetrieveMultipleRequest |
Response | RetrieveMultipleResponse |
Entity | See below. |
The following table shows the entities that support this message.
Remarks
To perform this action, the caller must have access rights on the specified entity instance. For a list of required privileges, see RetrieveMultiple Privileges.
Example
The following code examples shows how to use the RetrieveMultiple message.
[C#]
// Set up the CRM Service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the column set that indicates the fields to be retrieved.
ColumnSet cols = new ColumnSet();
// Sets the properties of the column set.
cols.Attributes = new string [] {"name", "accountid"};
// Create the condition expression.
ConditionExpression condition = new ConditionExpression();
// Set the condition for the retrieval to be when the city in the account's address is Sammamish.
condition.AttributeName = "address1_city";
condition.Operator = ConditionOperator.Like;
condition.Values = new string [] {"Sammamish"};
// Create the filter expression.
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 properies of the QueryExpression object.
query.EntityName = EntityName.account.ToString();
query.ColumnSet = cols;
query.Criteria = filter;
// Create the request object.
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
// Set the properties of the request object.
retrieve.Query = query;
// Execute the request.
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
[Visual Basic .NET]
' Set up the CRM Service.
Dim service As New CrmService()
service.Credentials = System.Net.CredentialCache.DefaultCredentials
' Create the column set that indicates the fields to be retrieved.
Dim cols As New ColumnSet()
' Set the properties of the column set.
cols.Attributes = New String() {"name", "accountid"}
' Create the condition expression.
Dim condition As New ConditionExpression()
' Set the condition for the retrieval to be when the city in the account's address is Sammamish.
condition.AttributeName = "address1_city"
condition.Operator = ConditionOperator.Like
condition.Values = New String() {"Sammamish"}
' Create the filter expression.
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.account.ToString()
query.ColumnSet = cols
query.Criteria = filter
' Create the request object.
Dim retrieve As New RetrieveMultipleRequest()
' Set the properties of the request object.
retrieve.Query = query
' Execute the request.
Dim retrieved As RetrieveMultipleResponse = CType(service.Execute(retrieve), RetrieveMultipleResponse)
Example 2
[C#]
// Return accounts whose owner's last name is not Cannon.
// Create a column set holding the names of the columns to be retrieved.
ColumnSet cols = new ColumnSet();
// Set the properties of the column set.
cols.Attributes = new string [] {"name", "accountid"};
// Create the condition expression.
ConditionExpression condition = new ConditionExpression();
// Set the condition for the retrieval to be when the last name of the account owner is not Cannon.
condition.AttributeName = "lastname";
condition.Operator = ConditionOperator.NotEqual;
condition.Values = new string [] {"Cannon"};
// Build the filter based on the condition.
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition};
// Create a LinkEntity to link the owner's information to the account.
LinkEntity link = new LinkEntity();
// Set the properties of the LinkEntity.
link.LinkCriteria = filter;
// Set the linking entity to be the account.
link.LinkFromEntityName = EntityName.account.ToString();
// Set the name of the attribute being linked to.
link.LinkFromAttributeName = "owninguser";
// Set the entity being linked to be the systemuser.
link.LinkToEntityName = EntityName.systemuser.ToString();
// Set the attribute linking to the systemuser to be the owninguser.
link.LinkToAttributeName = "systemuserid";
// Create the query.
QueryExpression query = new QueryExpression();
// Set the properties of the query.
query.EntityName = EntityName.account.ToString();
query.ColumnSet = cols;
query.LinkEntities = new LinkEntity[] {link};
// Create the request object.
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
// Set the properties of the request object.
retrieve.Query = query;
// Execute the request.
RetrieveMultipleResponse retrieved2 = (RetrieveMultipleResponse) service.Execute(retrieve);
Related Topics