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
A GunaleA Gunale 

Send an Email Notification to order related opportunity owner using Trigger (on order object)

ANUTEJANUTEJ (Salesforce Developers) 
Hi Gunale,

Is it that you want to send an email notification whenever a new order record is inserted or do you want to send the email at regular intervals?

can you elaborate on the scenario and the issue you are facing so as to check and respond appropriately.

Looking forward to your response.

Thanks.
AnudeepAnudeep (Salesforce Developers) 
Here is a pseudo-code
 
Trigger mailSend on Order(after insert){

List<Order> ordList = new List<Order>();//parent obj
set<Id> ordIds=new set<Id>();

for(Order ord: trigger.new){

ordIds.add(ord.id);

}

       //Relationship query to get opportunity user

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

        string[] toAddress = new string[]{}; 

        mail.setTargetObjectId(targetobjectid);

        toAddress.add(owner.email); //opportunity owner email (select owner.email from opportunity)

        system.debug('toAddress :'+toAddress);

        mail.setSaveAsActivity(false);

        mail.setToAddresses(toAddress);

        //System.debug(  mail.setTargetObjectId);

         mail.setTemplateId(et.id);    

       mail.setToAddresses(toAddress);       

        

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

}

 

}

NOTE: The code provided is an example. You'll need to review and make modifications for your organization.

Let me know if it helps