+ Start a Discussion
Stephanie Boggs 17Stephanie Boggs 17 

Is it possible to customize the addError standard page?

I have a trigger where if the Approval Process is Rejected and the Comments are blank the following page displays. My issue is that I would like to customize the error page so that the actual error is more prominent for the users. Is this possible?

Everything I see is related to error messages from VF pages.

trigger RequireRejectionComment on Contact (before update) 
{

  Map<Id, Contact> rejectedStatements 
             = new Map<Id, Contact>{};

  for(Contact inv: trigger.new)
  {
    /* 
      Get the old object record, and check if the approval status 
      field has been updated to rejected. If so, put it in a map 
      so we only have to use 1 SOQL query to do all checks.
    */
    Contact oldInv = System.Trigger.oldMap.get(inv.Id);

    if (oldInv.SAL_Approval_Status__c != 'Rejected' 
     && inv.SAL_Approval_Status__c == 'Rejected')
    { 
      rejectedStatements.put(inv.Id, inv);  
    }
  }
   
  if (!rejectedStatements.isEmpty())  
  {
    // UPDATE 2/1/2014: Get the most recent approval process instance for the object.
    // If there are some approvals to be reviewed for approval, then
    // get the most recent process instance for each object.
    List<Id> processInstanceIds = new List<Id>{};
    
    for (Contact invs : [SELECT (SELECT ID
                                              FROM ProcessInstances
                                              ORDER BY CreatedDate DESC
                                              LIMIT 1)
                                      FROM Contact
                                      WHERE ID IN :rejectedStatements.keySet()])
    {
        processInstanceIds.add(invs.ProcessInstances[0].Id);
    }
      
    // Now that we have the most recent process instances, we can check
    // the most recent process steps for comments.  
    for (ProcessInstance pi : [SELECT TargetObjectId,
                                   (SELECT Id, StepStatus, Comments 
                                    FROM Steps
                                    ORDER BY CreatedDate DESC
                                    LIMIT 1 )
                               FROM ProcessInstance
                               WHERE Id IN :processInstanceIds
                               ORDER BY CreatedDate DESC])   
    {                   
      if ((pi.Steps[0].Comments == null || 
           pi.Steps[0].Comments.trim().length() == 0))
      {
        rejectedStatements.get(pi.TargetObjectId).addError(
          'Please provide a rejection reason in the Comments field. Click the back arrow on your browser to go back to the Approve/Reject page.');

      }
    }  
  }
}

User-added image
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Stephanie Boggs,

May I suggest you please refer the below link for reference. Hope it will be helpful.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
Abhishek Raj 23Abhishek Raj 23
Hi

Did you find any solution or workaround for this?
Stephanie Boggs 17Stephanie Boggs 17
I did not.