+ Start a Discussion
AbrarAbrar 

Approval Process - Assigning Queue as a approver thru code

Facing a issue with Queue assignment as approver. As we can not dynamically assign queues in Approval Process we are first assigning it to a general user and reassigning it to a queue thru code. But while doing this, only if the current user is with Admin profile it is allowing to assign to a user and then reassign to a queue dynamically. but with restricted profiles(Without Modify All profile Permission) it is not happening. Finer details given below.  

 

Approval Process is on child object(Approval__c -with Public Read/Write setting) of Opportunity(Master detail relationship )

Using Without Sharing in Controller .

 

Code Snippet:

--------------------------------

 

 id QueueId;
    QueueId = [Select queueid from QueueSobject q where SobjectType = 'Approval__c' and q.Queue.Name = :queuename Limit 1].queueid;
    
       
    try
    {
    ProcessInstanceWorkItem workItemList = [Select p.ProcessInstance.Status, p.ProcessInstance.TargetObjectId,p.ProcessInstanceId,p.OriginalActorId,p.Id,p.ActorId From ProcessInstanceWorkitem p where p.ProcessInstance.TargetObjectId =:app and p.actorid=:DGSystemUserId order by createddate desc limit 1];
    workItemList.ActorId = QueueId;
    update workItemList;
    }

 

 

Appreciate your valuable response

Teach_me_howTeach_me_how

Facing the same issue now. does anyone resolve this?

Mark WilliamsonMark Williamson
I'm also facing this issue. Has anyone successfully got around this?
Robert Torres 6Robert Torres 6
What if instead of using a placeholder, you create an approval process based off a field -- say 'submitted for approval'  or something-- on the object. Then on button click, you can update the submitted for approval checkbox to true and use the following code to set the approver to a queue. The approval process should be using the option to allow the user to select the approver manually.  
 
sObject.is_Submitted__c = true;
update sObject;
Approval.ProcessSubmitRequest appreq = new Approval.ProcessSubmitRequest();
appreq.setObjectId(sObject.Id);
appreq.setNextApproverIds(new Id[] {queueId});
Approval.ProcessResult result = Approval.process(appreq);