Activity Forums Salesforce® Discussions How can i show Record Owner name in From/Reply in Email sent through Salesforce?

  • How can i show Record Owner name in From/Reply in Email sent through Salesforce?

    Posted by Rajan on May 1, 2018 at 8:24 am

    I want to show Record Owner name in From/Reply in Email sent through Salesforce. Can anyone help me in achieving this thing?

     

    Here is my code----
    list<String> listOfEmailsAddress = new list<String>();
    for(Lead leadobj : leadList){
    String [] toRecipients = new String[] {leadobj.NominatorEmail__c};
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    email.setToAddresses(toRecipients);
    email.setSenderDisplayName(leadobj.Owner_Name__c);
    email.setTargetObjectId(leadobj.Id);
    email.setUseSignature(false);
    email.setBccSender(false);
    email.setSaveAsActivity(true);
    email.setTemplateId(templateId);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    }

    Aman replied 6 years, 6 months ago 2 Members · 1 Reply
  • 1 Reply
  • Aman

    Member
    May 1, 2018 at 8:24 am

    Hi Rajan,

    SetSenderDisplayName won't work here. use setOrgWideEmailAddressId, by creating a custom setting and put the record owner in setting
    list<String> listOfEmailsAddress = new list<String>();
    for(Lead leadobj : leadList){
    String [] toRecipients = new String[] {leadobj.NominatorEmail__c};
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    email.setToAddresses(toRecipients);
    email.setTargetObjectId(leadobj.Id);
    email.setUseSignature(false);
    email.setBccSender(false);
    email.setTemplateId(templateId);
    if(listofEmailAddresses.size() > 0 ) {
    email.setOrgWideEmailAddressId(listofEmailAddresses.get(0).Id);
    }
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    }

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos