Answered by:
Auto Share opportunity record to specific users

Question
-
Hi CRM Support,
I'm working on a code that will auto share opportunity record to specific number of users. I have it work correctly when i set a specific id of a user. However i'm experiencing an error when i fetch specific users from another entity.. error shows the following message
Please see my plug-in codes below:
//grant access test codes-------------------------------------------------------------------------------START
//Fetch Users to that will have access to the opportunity
QueryExpression queryLeadcodeAssignee = new QueryExpression("nexus_nexus_leadcode_systemuser");
queryLeadcodeAssignee.ColumnSet = new ColumnSet(new string[] { "systemuserid" });
queryLeadcodeAssignee.Criteria.AddCondition("nexus_leadcodeid", ConditionOperator.Equal, ((EntityReference)PostImageForOpportunities["nexus_leadcode_lookup"]).Id);
queryLeadcodeAssignee.PageInfo.ReturnTotalRecordCount = true;
EntityCollection LeadcodeAssigneeEntity = service.RetrieveMultiple(queryLeadcodeAssignee);
foreach (Entity LeadcodeAssigneeEntityResult in LeadcodeAssigneeEntity.Entities)
{
var Rights = AccessRights.ReadAccess | AccessRights.WriteAccess ;
var sampleuser1 = new EntityReference("systemuser", ((EntityReference)LeadcodeAssigneeEntityResult["systemuserid"]).Id);//new Guid("E9007311-358D-E211-A12C-36D7C49CDBE8"));
var principalAccess = new PrincipalAccess
{
// Gives the principal read write access
AccessMask = Rights,
// Set the PrincipalAccess Object's Properties
Principal = sampleuser1
};
// Create the Request Object
var grantAcessRequest = new GrantAccessRequest();
// Set the Request Object's properties
grantAcessRequest.PrincipalAccess = principalAccess;
// Set the Target. In my case it is account record
var entityReference = new EntityReference("opportunity", PostImageForOpportunities.Id);
//throw new InvalidPluginExecutionException("EntityReference");
grantAcessRequest.Target = entityReference;
//Execute the Request
service.Execute(grantAcessRequest);
}
//grant access test codes-------------------------------------------------------------------------------ENDAdvance thank you for you help..
Regards,
Honey Dulatre
Thursday, May 8, 2014 8:41 AM
Answers
-
the error message is telling us that the 'object' being of type 'guid' could not be cast to 'entityReference'
within your code your making casts to EntityReference, one of them is causing the problem.
Breakpoint & Debugger is your best friend
- Proposed as answer by Payman BiukaghazadehEditor Wednesday, June 4, 2014 2:26 PM
- Marked as answer by Honey Dulatre Thursday, June 5, 2014 5:28 AM
Monday, June 2, 2014 1:16 PM -
Hi,
This is not related to your question, but better to say. Be aware about sharing. Its design is for limited usage, not for bulk sharing. When you share something for multiple users systematically, it means after a while you could have lots of shared data. This could impact CRM in two ways:
1- High sharing ratio shows inefficiency of your security design. Business units, users, groups and roles could be revised to prevent this sharing.
2- When you share lots of data, after a while the performance of CRM could drastically decrease.
As I said this is not your question's answer, but it is related to the automatic sharing plugins.
- Marked as answer by Honey Dulatre Thursday, June 5, 2014 5:33 AM
Wednesday, June 4, 2014 2:31 PMModerator
All replies
-
the error message is telling us that the 'object' being of type 'guid' could not be cast to 'entityReference'
within your code your making casts to EntityReference, one of them is causing the problem.
Breakpoint & Debugger is your best friend
- Proposed as answer by Payman BiukaghazadehEditor Wednesday, June 4, 2014 2:26 PM
- Marked as answer by Honey Dulatre Thursday, June 5, 2014 5:28 AM
Monday, June 2, 2014 1:16 PM -
Hi,
thank you for the support.. I have resolved this :)
Thank you again,
Regards,
Honey
Wednesday, June 4, 2014 10:35 AM -
Hi,
This is not related to your question, but better to say. Be aware about sharing. Its design is for limited usage, not for bulk sharing. When you share something for multiple users systematically, it means after a while you could have lots of shared data. This could impact CRM in two ways:
1- High sharing ratio shows inefficiency of your security design. Business units, users, groups and roles could be revised to prevent this sharing.
2- When you share lots of data, after a while the performance of CRM could drastically decrease.
As I said this is not your question's answer, but it is related to the automatic sharing plugins.
- Marked as answer by Honey Dulatre Thursday, June 5, 2014 5:33 AM
Wednesday, June 4, 2014 2:31 PMModerator -
Hi Payman,
Thanks for the advise. I'll take note of this..
Regards,
Honey
Thursday, June 5, 2014 5:32 AM