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

  • 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 '17 at 5:08

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};

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

If you need any assistance let me know.

  • 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 '17 at 3:12

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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.