function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Cris9931Cris9931 

add an image to display as error in my trigger

Hello, I want to show an image when my trigger activates; I created this code but it's not working. I'm not sure, if it is possible to display an image in the addError function...?

trigger ContactCreationForServiceMaxUsers on Contact (Before insert) {

       String baseURL = String.valueof(URL.getSalesforceBaseUrl());
       String imageURL {get;set;}
       system.debug('<<baseURL>>' + baseURL);
       Boolean isBaseURL = baseURL.contains('https://sig-cb--Full.cs88.my.salesforce.com');
       System.debug(' >> String.valueof(URL.getSalesforceBaseUrl()) >>'+baseURL ); 
       User currentUser = [SELECT Id, Profile.Name FROM USER WHERE Id =:UserInfo.getUserId()]; 
       List< document > documentList=[select Name from document where FolderID='0159E0000002tNp' limit 1];
       if(documentList.size()>0)
      {
          imageURL=imageURL+documentList[0].Name;
      }
       Contact c = new Contact(); 
       System.debug(' >> isBaseURL >>'+isBaseURL ); 
       System.debug(' >> currentUser.Profile.Name>>'+currentUser.Profile.Name ); 
   
     for(Contact c : Trigger.New){ 
          if(isBaseURL == TRUE  && currentUser.Profile.Name == 'SIG-FSM-Super User'){
           c.addError(imageURL + ' ' + 'enter som'); 
          } 
     } 
}

the trigger works and it displays   '  null enter som '. My imageURL seems to be null here...
AbhishekAbhishek (Salesforce Developers) 
Hi Sarah,

Your query is answered in the below blogs,

https://salesforce.stackexchange.com/questions/147828/customize-error-message-for-trigger-and-display-error-message-below-the-field

https://developer.salesforce.com/forums/?id=906F00000008y4KIAQ

https://www.forcetalks.com/salesforce-topic/how-to-add-error-message-in-a-salesforce-apex-trigger/

You can change the code based on the above.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.