+ 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 );
         }
      else
mail.setSubject(    'There is no company name' );


i has create like this but its not working.
 
nbknbk
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 id=:Con.id]; 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 }); } }
Sforce.NinjaSforce.Ninja
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 : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm#apex_System_SObject_get

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

https://help.salesforce.com/apex/HTViewHelpDoc?id=cs_about.htm