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
carmilyn.c martincarmilyn.c martin 

merge fields not working on @invokablemethod in Process builder


We have a process builder created that will fire if a new record is created and the action is to create another Action and the to send an email. Since we need to cc the managers we created an @invocablemethod and incorporate the Email Template we created the email is being sent however, the merge fields are all blank. Here is our Apex Class: 

public class SendEmailToRep_CcDMs{

    public static void GetUserRoleId(List<Id> proposedTerritory)
        string tempName = 'DS_Proposing_NICM_Tgt_Account';
        List<PTMS_Users_and_Role__c> userManager = [SELECT Id,Name,Manager__c,User__c,Manager__r.Email,User__r.Email,User__r.Id 
                                                    FROM PTMS_Users_and_Role__c 
                                                    WHERE Id IN:proposedTerritory];
        Id templateId; 
        templateId = [select id, name from EmailTemplate where developername = :tempName].id;                                            
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
                    for(PTMS_Users_and_Role__c ptmsUsers: userManager){
                                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                                    //Send email to Rep
                                    /*List<String> sendTo = new List<String>();
                                    mail.setToAddresses(sendTo); */
                                    mail.setSenderDisplayName('Vector Team');
                                    //cc Manager
                                    List<String> ccTo = new List<String>();
    }//end of method
}//end of class

Please help. 

Thank you. 

Maharajan CMaharajan C

Hi Carmilyn,

In the Email Template if you refering the custom objects then please use the merge the fields from custom object.

Or refer this below link may be it will help to you.

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!