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
kamal3883kamal3883 

Email Signature in Apex

Hi,

Can anyone tell me is it possible to extract email signature(Salesforce Standard present in My Email Settings) in Apex. We just want to extract through apex so that we can append it in some pages.

Thanks
 
SonamSonam (Salesforce Developers) 
Currently I believe its not possible to access the  Signature field  drectly through APEX.We have an existing idea for the same :
https://success.salesforce.com/ideaView?id=08730000000aZvWAAU which is under point threshold.

There is a workaround for the same that is to copy the value of the field to another custom field and them make use of it as shown by one of the users on the Idea:

trigger CopySignature on User (before update, before insert) {
    for (User user : Trigger.new)
        user.Signature_copy__c = user.Signature  ; 

}
SamHowleSamHowle
Hi Kamal,

You can access the user's email signature via the code below. No need for a trigger or custom field. However, it may remove line breaks and can cause formatting issues. I used this code to insert into an email message's htmlbody and was able to replace all ASCII line breaks with HTML line breaks. I imagine you can do a similar find/replace for visualforce pages or whatever destination formatting you might need.
 
User currUser = [Select Id,Signature from User where Id=:userinfo.getuserId()];
            string userSignature = currUser.Signature;
             if (String.isNotBlank(userSignature)) {
                 userSignature = userSignature.replace('\n','<br>');
}