2

enter image description hereI need your help.I am parsing approval email response via email service.Everything is working as expected. But When I am sending any record for approval and then Assigned approver is replying through email as Approve or Approved, the record got approved but in Approval history section my name is coming as actual approver all the time.I tried many things but it's not working.How to change actual approver based on who is replying to that email.I see some people faced same issue but I didnt see any work around.Please see attached for more details

code snippet

 if(firstLine.containsIgnoreCase('Approved') || firstLine.containsIgnoreCase('Approve') || firstLine.containsIgnoreCase('OKAY') || firstLine.containsIgnoreCase('YES')) {
                    approvalreq();         
                    }
public void approvalreq(){
    List<ProcessInstance> pi =[SELECT Id FROM ProcessInstance WHERE TargetObjectId=:recordid];
    List<ProcessInstanceWorkitem> piw =[SELECT Id,ActorId,ProcessInstanceId FROM ProcessInstanceWorkitem WHERE ProcessInstanceId=:pi[0].Id];
        Approval.ProcessWorkitemRequest req2 =new Approval.ProcessWorkitemRequest();
        req2.setAction('Approve');
        req2.setComments(secondLine);
        req2.setWorkitemId(piw[0].Id);

        Approval.ProcessResult result2 =Approval.process(req2);     
    }
  • Can you paste the code for what you are trying to do? – Ritika_SFDC Dec 2 '16 at 18:24
  • Hi Ritika, I have updated question accordingly. – Ayush Dec 4 '16 at 6:42
0

The standard functionality to allow a user to approve by responding to an email is called email approval response.

By using the standard functionality, you don't need to set up your own email service to handle the emails or parse the response for "approved"-like keywords, and the user sends the email will be recorded as the approver in the approval process history.

| improve this answer | |
  • Hi Martin I need to parse additional keywords also like Okay or I am Okay. Dat's why I am using email service – Ayush Dec 4 '16 at 6:38
  • @Ayush no matter who sends the email, the inbound email handler will be run with the admin as the context user and all actions will be recorded as being done by the admin. – martin Dec 5 '16 at 0:29
  • 1
    clarification -- email service running user is the context user defined in the metadata, not necessarily an admin; more likely a headless user – cropredy Dec 5 '16 at 2:52
  • good point, the context user doesn't have to be an admin @cropredy – martin Dec 5 '16 at 3:32
  • @ Martin @ Cropredy - That means in approval history actual approver will be a context user ? We can't set that to user that is replying to that email ,will be a actual approver? – Ayush Dec 5 '16 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.