There are scenarios where you would want to retrieve records based on some condition.
To do that with the use of C#,below code can be used.
For example i have used account entity.
QueryExpression query = new QueryExpression
{ EntityName = "account", ColumnSet = new ColumnSet("name", "accountid") };
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "name";
condition1.Operator = ConditionOperator.Equal;
condition1.Values.Add("Your filter value");
FilterExpression filter1 = new FilterExpression();
filter1.Conditions.Add(condition1);
query.Criteria.AddFilter(filter1);
EntityCollection accountname = _service.RetrieveMultiple(query);
Other example with contact entity.
QueryExpression query = new QueryExpression
{ EntityName = "contact", ColumnSet = new ColumnSet("firstname", "lastname", "emailaddress1", "contactid", "donotsendmm") };
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "firstname";
condition1.Operator = ConditionOperator.Equal;
condition1.Values.Add(firstname);
ConditionExpression condition2 = new ConditionExpression();
condition2.AttributeName = "lastname";
condition2.Operator = ConditionOperator.Equal;
condition2.Values.Add(lastname);
ConditionExpression condition3 = new ConditionExpression();
condition3.AttributeName = "emailaddress1";
condition3.Operator = ConditionOperator.Equal;
condition3.Values.Add(email);
FilterExpression filter1 = new FilterExpression();
filter1.Conditions.Add(condition1);
filter1.Conditions.Add(condition2);
filter1.Conditions.Add(condition3);
query.Criteria.AddFilter(filter1);
EntityCollection accountname = _service.RetrieveMultiple(query);
Cheers!
Happy Development.
To do that with the use of C#,below code can be used.
For example i have used account entity.
QueryExpression query = new QueryExpression
{ EntityName = "account", ColumnSet = new ColumnSet("name", "accountid") };
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "name";
condition1.Operator = ConditionOperator.Equal;
condition1.Values.Add("Your filter value");
FilterExpression filter1 = new FilterExpression();
filter1.Conditions.Add(condition1);
query.Criteria.AddFilter(filter1);
EntityCollection accountname = _service.RetrieveMultiple(query);
Other example with contact entity.
QueryExpression query = new QueryExpression
{ EntityName = "contact", ColumnSet = new ColumnSet("firstname", "lastname", "emailaddress1", "contactid", "donotsendmm") };
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "firstname";
condition1.Operator = ConditionOperator.Equal;
condition1.Values.Add(firstname);
ConditionExpression condition2 = new ConditionExpression();
condition2.AttributeName = "lastname";
condition2.Operator = ConditionOperator.Equal;
condition2.Values.Add(lastname);
ConditionExpression condition3 = new ConditionExpression();
condition3.AttributeName = "emailaddress1";
condition3.Operator = ConditionOperator.Equal;
condition3.Values.Add(email);
FilterExpression filter1 = new FilterExpression();
filter1.Conditions.Add(condition1);
filter1.Conditions.Add(condition2);
filter1.Conditions.Add(condition3);
query.Criteria.AddFilter(filter1);
EntityCollection accountname = _service.RetrieveMultiple(query);
Cheers!
Happy Development.
Comments
Post a Comment