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
WikWik 

Error in trigger

Hi,

trigger send_notification on Quote (after update) {

  Quote inquery = trigger.new[0]; 
  Quote.email__c = 'Gaurav.Raj@fs.utc.com';
  String[] toAddresses = new String[] {inquery.email__c}; 
 
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  //mail.setTargetObjectId(inquery.OwnerID);
  mail.setSenderDisplayName('Salesforce Support');
  mail.setUseSignature(false);
  mail.setBccSender(false);
  mail.setSaveAsActivity(false);

 if (Trigger.isUpdate) { 
    if(inquery.XYZ__c == 'True') {
          EmailTemplate et=[Select id from EmailTemplate where ID=:'00X6000000126rL'];
          mail.setTemplateId(et.id);
          Messaging.SendEmailResult [] r = 
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});   
      } 
      }
      }

it throws an error : 
Error: Compile Error: Expression cannot be assigned at line -1 column -1
 
BalajiRanganathanBalajiRanganathan
the following line has issue. ":" is used to bind variables. so try removing that.

EmailTemplate et=[Select id from EmailTemplate where ID=:'00X6000000126rL'];

try this updated code.
EmailTemplate et=[Select id from EmailTemplate where ID='00X6000000126rL'];

also you have to bulkify your code and use custom setting instead of hardcoding the id in the above SOQL.  Please refer the best practices link below on how to achive this

https://developer.salesforce.com/page/Apex_Code_Best_Practices

 
WikWik
Can you help me with what exactly needs to be modified, am confued .
WikWik
i meant the bulkifying part
BalajiRanganathanBalajiRanganathan
Do not use trigger.new[0]. this means you trigger handles only one record. if the trigger is executed when multiple records are updated in a single transaction (using dataloader or api) you code will do the work only for single record.

here is the bulikified version
trigger send_notification on Quote (after update) {
EmailTemplate et=[Select id from EmailTemplate where ID=:'00X6000000126rL'];

 for (Quote inquiry : trigger.new) { 
  inquiry.email__c = 'Gaurav.Raj@fs.utc.com';
  String[] toAddresses = new String[] {inquery.email__c}; 
 
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  //mail.setTargetObjectId(inquery.OwnerID);
  mail.setSenderDisplayName('Salesforce Support');
  mail.setUseSignature(false);
  mail.setBccSender(false);
  mail.setSaveAsActivity(false);

 if (Trigger.isUpdate) { 
    if(inquery.XYZ__c == 'True') {
          mail.setTemplateId(et.id);
          Messaging.SendEmailResult [] r = 
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});   
     } 
   }
 }
}

 
BalajiRanganathanBalajiRanganathan
In the above code remove the colon : in th email template SOQL
EmailTemplate et=[Select id from EmailTemplate where ID='00X6000000126rL'];