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
SFDC DummySFDC Dummy 

Mail Message with Subject Line

Hi All

I have created a apex class for sending mail.but my requirment is subject line is different for diffrenet object.

mainly i have created this for task object for assining task ,when user assign any task depending on custom object/standard object it will send a mail with proper subject line

for ex

if(acc.Company_Name__c !=null)
         mail.setSubject(    +  acc.Company_Name__c );
mail.setSubject(    'There is no company name' );

i has create like this but its not working.
Can you please post your complete code, it will be useful to identify the issue
SFDC DummySFDC Dummy
public class SendEmail { private final Contact Con; public SendEmail(ApexPages.StandardController controller) { this.Con=(Contact)controller.getRecord(); } public Void SendEmail() { Contact varcon=[Select id,name,Email from Contact where]; account acc=[select id ,Company_Name__c from account limit 1]; System.debug('Contact Emai ID====>'+varcon.Email); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String VarEmailSetting=varcon.Email; String[] toAddresses = new String[] {VarEmailSetting}; mail.setToAddresses(toAddresses); if(acc.Company_Name__c !=null) { mail.setSubject( + acc.Company_Name__c ); } else mail.setSubject( 'There is no company name' ); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } }
Hey project dummy, please use the < > button on the editor to put your code. It formats the code and helps us read.
Shashikant SharmaShashikant Sharma
You could use sObject get method to retrive the value fro object dynamically.

see this :

Now I think there will be different fields for different objects you could configure them using Custom Settings