+ Start a Discussion

Approval by email does not work with Apex

Hi all, 


I want to use the approval-by-email  functionality on an approval process that I have created. When I kick this approval process of via the standard Salesforce user interface (meaning, I have the submit for approval button included in the page layout), it all works well. The approver receives an email with the reply-to field filled with a salesforce email address. 


But, there are reasons why I cannot start this approval by using the button in the page. Instead, I had to create a button in the page that calls an VF page. In the constructor of the controller for that page I kick off the approval process (for code see below). This works perfectly well. 


But, If the approval process is started this with (via apex) the email notification that is sent out does NOT have the reply-to field filled with a salesforce address, and consequently, replying to this email does not approve or reject the object. 


Does anybody have an idea how to solve this?





// Create an approval request for the Object           

Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();

req1.setComments('Submitting request for approval.');



// Submit the approval request           


    Approval.ProcessResult result = Approval.process(req1);             

    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'This Object has been succesfully submitted for approval'));                    



catch (Exception e) {

    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));            }