function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfadm sfdevsfadm sfdev 

Avoid Error: MIXED_DML_OPERATION vol. 2

Hello,

I'd like to continue my conversation from my previous discussion with subject "Avoid Error: MIXED_DML_OPERATION".

What I'd like know now is how to set the permission set
PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = '0PS7E000000DBGA', AssigneeId = currentuserId);
when the Approval process is over.

The Approval process is actually over when the stage of the current Opportunity is changed to "Proposal".
Opportunity Stage

In order to find out when the Opportunity stage will be changed from "Discovery" to "Proposal" I was thinking of implementing an event listener which will monitor the Opportinity stage. And when the Opportunity stage is changed to "Proposal" the listener will invoke the DeletePErmissionSetAssignemt() method. I know this can be achieved in Java but in I'm not fully aware how to implement such an event listener in Salesforce. Could you please advise and give an example of how to implement an event listener in Salesforce? If there is no such way can you suggest an appropriate solution to what I'm trying to achive?

Thank you
karthikeyan perumalkarthikeyan perumal
Hello 

 you can  assign Permission set  to user when the status changes through a trigger. 

 Setp1 : Write a trigger  on Opp After update. 

get the Opp  status 

If Condition Check the if its "Proposal"

Added the below Code:
 
PermissionSet ps = [select Id from PermissionSet where Name = '<permissionsetname>'];

PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = ps.Id, AssigneeId = UserInfo.getUserId());

insert psa

Hope it will clear. it may help you to solve your probelm 

Thanks
karthik

 
karthikeyan perumalkarthikeyan perumal
Hello 

And Another Suggestion:  (with out Code)

Create Flow for PermissionSetAssignment
using process builder to excute the flow Assignment 

Thanks
karthik
sfadm sfdevsfadm sfdev
Hi Karthik,

Thank you for your comment and advise.

I'll try to create an after update trigger in the Opportunity object,

but I was wondering could you be more specific and can you please give an example on how to create flow for PermissionSetAssignment using process builder?

Thank you
karthikeyan perumalkarthikeyan perumal
Hello

sorry for late reply

Kinldy go through below link to assign permission set using process builder. 
https://automationchampion.com/2014/07/18/automatically-add-permission-sets-to-new-user/

Hope this will help you.  Make it solved its clear for you.

Thanks
karthik