Share Entity record with Team

Posted: March 24, 2013 in CRM 2011, CRM5, Microsoft Dynamics CRM
Tags: , , ,

          Below is the sample code to share entity record with team in MS CRM 2011

            var teamReference = new EntityReference(“team”, teamId);
            var grantAccessRequest = new GrantAccessRequest
                PrincipalAccess = new PrincipalAccess
                    AccessMask=AccessRights.ReadAccess | AccessRights.WriteAccess,        

                Target=new EntityReference(“lead”,recordId)


           // Get teamId from below function

private Guid GetTeamId(string teamName,OrganizationService service)
            Guid teamId=Guid.Empty;
            QueryByAttribute query = new QueryByAttribute();
            ColumnSet cols = new ColumnSet();

            query.ColumnSet = cols;
            query.AddAttributeValue(“name”, teamName);
            query.EntityName = “team”; 

            EntityCollection entityCollection = (EntityCollection)service.RetrieveMultiple(query);              
            if (entityCollection.Entities.Count > 0)
                    Entity entity =entityCollection.Entities[0];
                    teamId = entity.Id;
            return teamId;          


I have already posted the same for CRM 4.0. Please find the reference link below.



Leave a Reply

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

You are commenting using your 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