You need to sign in to do that
Don't have an account?
nidhi 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 = trigger.new[0];
system.debug('mailid'+Ld.Mail_To_Vista_First__c);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//mail.setTargetObjectId('Ld.OwnerID');
system.debug('ownerID'+Ld.OwnerID);
mail.setSenderDisplayName('do-not-reply@snapdeal.com');
mail.setUseSignature(false);
mail.setBccSender(false);
mail.setSaveAsActivity(false);
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';
mail.setSubject(subject);
//Message with line break tag
mail.setHtmlBody('<html><body>Your '+ Ld.Seller_Code__c+' an unique id with Snapdeal.com 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};
mail.setToAddresses(addresses);
}
system.debug('mail value'+mail);
if(toAddresses != null)
{
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
system.debug('sendemail'+r);
}
}
}
}
Awaiting for your reply.
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 = trigger.new[0];
system.debug('mailid'+Ld.Mail_To_Vista_First__c);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//mail.setTargetObjectId('Ld.OwnerID');
system.debug('ownerID'+Ld.OwnerID);
mail.setSenderDisplayName('do-not-reply@snapdeal.com');
mail.setUseSignature(false);
mail.setBccSender(false);
mail.setSaveAsActivity(false);
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';
mail.setSubject(subject);
//Message with line break tag
mail.setHtmlBody('<html><body>Your '+ Ld.Seller_Code__c+' an unique id with Snapdeal.com 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};
mail.setToAddresses(addresses);
}
system.debug('mail value'+mail);
if(toAddresses != null)
{
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
system.debug('sendemail'+r);
}
}
}
}
Awaiting for your reply.
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.