Tag Archives: Approval Process

Salesforce Sandbox Workflow & Approval Process email alert not working

Its the effect from Spring release13 all the Sandboxes Access Email level are set default to “System Emails” only, We need to change it here -> Setup -> Email Administration -> Deliverability -> set the Access to Send Email from “System Only” to “All Emails”.

Restrict multiple approval for a single user to a single record in Salesforce

I had a requirement to restrict multiple approval for a single user to a single record. There were multiple steps of approval process and the approver may be in different queue or as a manager for a user.

So, I implemented it using a trigger. In this article I’ll demonstrate how to implement it.
Here Application__c is the object, on which 3 steps approval process has implemented.
A custom check box field Check_Approver__c has set value to true, in all 3 steps field update action.

In below trigger I filtered the ProcessInstanceStep object records with current user Id in ActorId and the object Id (here object Id means record Id) in ProcessInstance.TargetObjectId.

  • If an User will approve or reject a record, then the SOQL query will return a single record.
  • If the SOQL query return a record, then trigger will throw an error message.

Trigger source code:

trigger ApplicationTrigger on Application__c (before Update)
{
    if(trigger.isUpdate){

        Id currentUserId = UserInfo.getUserId();
        for(Application__c sf: trigger.new){   
                  
            if(sf.Check_Approver__c == true){
              
                List<processinstancestep> existingApprovals = [SELECT ActorId
                                    FROM ProcessInstanceStep WHERE ProcessInstance.TargetObjectId = :sf.Id
                                    AND (StepStatus = 'Approved' OR StepStatus = 'Rejected')
                                    AND ActorId = :currentUserId];
                                      
                if(existingApprovals != null){
                  
                    if(existingApprovals.size() > 0){

                        sf.addError('You have already approved or rejeted the record.');
                    }
                }                  
             }
         }                         
    }
}

Salesforce: Add Approve/Reject Link in Email template for approval

Sometimes we need to customize the email that goes out to an approver with the record approve link, Where can approver find the link to approve or reject the record.

We can use the Merge field {!ApprovalRequest.External_URL} or {!ApprovalRequest.Internal_URL} to add approve link in email template.

Follow below steps:

  • In the Available Merge Fields select Field Type as Approval Fields.
  • Select Field as Internal Approval URL or External Approval URL.
  • Copy and paste the merge field value into your template.

Note: Approval process merge fields can be used in email templates, but not mail merge templates. Because email notifications to a queue aren’t intended for an external audience, any instances of the merge field {!ApprovalRequest.External_URL} in the email template are sent as the equivalent internal URL.