I have tried all the ways still its not working. Can you please help....


trigger UserDelegatedApproverExpiration on User (before update){

    for(User u: Trigger.new)
       String ecUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/apex/delegatedUser?id='+u.id;
       String ecMsg = '<a style=\'color:1B2BE8\' target="_blank" href="'+ecUrl+'"> Here </a>';

         if(u.DelegatedApproverId != null){
            if(u.Delegated_Approver_Expiration_Date__c == null && u.Delegated_Approver_Start_Date__c == null){
             u.addError('<br/>Please enter Delegated Approver from '+ ecMsg +' <br>', True);

Error :

Error: Invalid Data. 
Review all error messages below to correct your data.
<br/>Please enter Delegated Approver from <a style='color:1B2BE8' target="_blank" href="https://cs26.salesforce.com/apex/delegatedUser?id=00560000002OwWGAA0"> Here </a> <br>
  • Markup has no place in a trigger context. Think about how that would look from data loader. This sort of error message should be added from your controller instead, if you are on a page. – Adrian Larson Sep 28 '16 at 14:06
  • This error message is displaying on User Object(Standard) record. Want to display with the link... – Vivekananda Reddy Sep 28 '16 at 14:15

The issue you are having is with this line:

u.addError('<br/>Please enter Delegated Approver from '+ ecMsg +' <br>', True);

The second argument needs to be false if you want the HTML link to appear

u.addError('<br/>Please enter Delegated Approver from '+ ecMsg +' <br>', false);

from a sample of code I wrote

foo.addError('blah ' + 
             '<a href="' +
             '/' + someId +
             '">' +
             somefriendlyTextForLink +
| improve this answer | |
  • Its not possible to display URL error message in USER object. We already contacted SFDC Team. Thank you! – Vivekananda Reddy Oct 12 '16 at 8:35

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.