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
nidhi aryanidhi arya 

Code not working in production

Hi All,

I have written down a trigger(Trigger which sents out an email alert when the different fields are updated from the backend without editing the record) which is working fine in sandbox .But when I have deployed it to Production Its not working at the first go. But second time when AI go and update the record manually only then my code runs.

Also for referenece there is one other code which is running after update but that is running successfully.

Code of My Trigger-
trigger send_notification on Lead (after update) {
system.debug('send notification trigger active');
  Lead Ld =[0];
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();


if (Trigger.isUpdate) {
  system.debug('condition value'+Ld.Stage__c);
    if(Ld.Stage__c == 'Pre On-boarding' && Ld.Seller_Code_Generated__c == true && Ld.Pincode_Mapping_Completed__c == False &&( Ld.Mail_To_Vista_First__c !=null || Ld.Mail_To_Vista_First__c !='') ){
      // create email content
         system.debug('Lead Name : '+Ld.Name);
        String subject = 'Hi Partner';
     //Message with line break tag
        mail.setHtmlBody('<html><body>Your  '+ Ld.Seller_Code__c+' an unique id with has been emailed to you.Please refer this code for any communication with us.<br>Best Regards<br>Snapdeal Team');   

     // add recipients
      String toAddresses =  Ld.Mail_To_Vista_First__c;
      system.debug('mail value +++'+ toAddresses);
      if( string.isNotBlank(toAddresses))
  system.debug('value of toaddress'+string.isNotBlank(toAddresses));
     //Set your too addresses here based on task criteria
     String[] addresses = new String[] {toAddresses};
      system.debug('mail value'+mail);
     if(toAddresses != null)
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

Awaiting for your reply.
Pavan Kumar KajaPavan Kumar Kaja
Hi Nidhi Arya,

Your trigger will work on after update action happend on that object on first time operation is insert so trigger is not firing. so thats why your trigger is firning second time.

Let me know if u hav any concerns.