0

I wish to send a mail based on some condition (one of the company field's picklist value is airline) to the people who's email email ids are in custom field . If it is possible how can we send?..

Thanks in advance

1
  • Not with that method unless the standard email field also contains the same email. You would have to pull the email address yourself and use setToAddresses
    – Eric
    Mar 25, 2017 at 5:08

2 Answers 2

0

Please refer the below code. It might help for your need.

    EmailTemplate et; //using email template

    Messaging.SingleEmailMessage mail;
    String[] sendTo;        
    Contact cont = [SELECT Id,Name,email from Contact WHERE email != null LIMIT 1];

    //Sending emails to defined email template

    for(ContractObj__c ct:contracts)
    {
        mail = new Messaging.SingleEmailMessage();

        et = [SELECT Id,Name,Body,HtmlValue,Subject from EmailTemplate ];        
        sendTo= new String[]{ct.Email__c};
        mail.setToAddresses(sendTo);               
        mail.setTemplateId(et.id); 
        mail.setWhatId(ct.id);
        mail.setTargetObjectId(cont.Id);           

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }

If you need any assistance let me know.

1
  • send a mail based on some conditions (one of the custom field's picklist value is airline then send to one mail id or different mail id)
    – Reddy
    Mar 27, 2017 at 3:12
0

soql the email id of the particular contact and assign it to the setTargetObjectId and also pass the object id [mail.setWhatId(objectId); // Object Id for which data will be sent]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .