Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

AssociateRequest – MS CRM 2011

Leave a comment

Problem:
Suppose you have create a new contact and since there is a relationship between contacts and Accounts by default , so you would like to relate this contact to a specific account or to many accounts.

Here comes the Associate Request !!

Solution:
we will use a class called “Associate Request”  which links records to each user assuming there is a relationship between the entities which records belong to .
Code:


IOrganizationSericce service;  // instance of the organization serivce

Contact contact;  //The contact you have

Account account; //The account you have and which you like to link the contact too.

AssociateRequest  contactToAccount = new AssociateRequest
{

//The contact record

Target = new EntityReference(contact.EntityLogicalName, contact.contactId),

//The list of account you would like the contact to be linked with (in this case we have only one account)

RelatedEntities = new EntityReferenceCollection
{
new EntityReference(Account.EntityLogicalName,account.accountId)
},

Relationship = new Relationship(“name of the relationship already existing”)
};

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s