The sample code below demonstrates how to share a contact record with a user. This is very helpful if you want to allow multiple users to own a record.
My solution to the problem was to share the record with users when the “Secondary Owner” was set on the form.

        SecurityPrincipal principal = new SecurityPrincipal();
        principal.Type = SecurityPrincipalType.User;
        principal.PrincipalId = new Guid(userid.ToString());

        // Create the PrincipalAccess Object
        PrincipalAccess principalAccess = new PrincipalAccess();
        principalAccess.Principal = principal;
        // Gives the principal access to read
        principalAccess.AccessMask = AccessRights.ReadAccess | AccessRights.AppendAccess | AccessRights.AppendToAccess | AccessRights.WriteAccess;

        // Create the Target Object for the Request
        TargetOwnedContact target = new TargetOwnedContact();
        target.EntityId = new Guid(recordID.ToString());

        // Create the Request Object</span>
        GrantAccessRequest grant = new GrantAccessRequest();
        grant.PrincipalAccess = principalAccess;
        grant.Target = target;

        // Execute the Request
        GrantAccessResponse granted = (GrantAccessResponse)service.Execute(grant);
Advertisements