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
vfexp31.3955631467313875E12vfexp31.3955631467313875E12 

sends email-template to customer

HI,

        I want to sends email-template to contact, based upon Quote-item Field, Actually in Quote-item i have a field Update_del, when the field is true at that time i want to sends email template,

    Here quote-Item is child to Quote, having master-details relation ship, in Quote i have a field called Email__c i want to sends email-template to the address which mention in the Email__c field based upon Quote_item Object

  I tried Below But i am getting Error at Soql Query

   trigger emailtemplate2 on Quote_Item__c(after update)
{

List<Quote_Item__c> oList = Trigger.new;
List<Quote_Item__c> nList = trigger.old;

  if(oList[0].Updated_del__c !=nList[0].Updated_del__c) {

      Set<Id> QuoteItemIds= new Set<Id>();
 List<Quote__c>  sList = [select id,Email__c from Quote__c where Quote__r.Email__c =:nList[0].Quote__c.Id limit 1];
   // Error Occuring Point

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

     if(oList[0].Quote_Item__c== 'true') {
      EmailTemplate et=[Select id from EmailTemplate where name = 'quote3' limit 1];
      mail.setTemplateId(et.id);
      mail.setToAddresses(new String[] {sList[0].email});
      mail.setTargetObjectId(sList[0].id);
      mail.setSaveAsActivity(false);
  Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});  


 
}

}

}
VikashVikash (Salesforce Developers) 
Hi,

Please modify- where Quote__c = :nList[0].Quote__c. Also change mail.setToAddresses(new String[] {sList[0].email}); instead of email, use email__c

Thanks
Vikash_SFDC