You need to sign in to do that
Don't have an account?
Trigger failing on live but works on sandbox
I have deployed a trigger to live but it seems to not populate the service Contract but in sandbox it does.
The name of the fields are the same. The trigger is
I have tested the below on our test system and it works correctly. The fields are the same in Live and Sandbox but the trigger will not populate the service contract field on a case.
I have tried removing the recordtype, using specific account but no luck on Live.
trigger UpdateServiceContract on Case (before insert,before update, after update) {
if (trigger.isBefore && trigger.isInsert) {
for (Case c : trigger.new) {
if (c.RecordTypeID == '012D0000000NWyPIAW')
if (c.service_contract__c == NULL){
try{
//c.Service_Contract__c = [select Id from ServiceContract where AccountId ='810D0000000Cfza' and Primary_Service_Contract__c = True].id;
c.Service_Contract__c = [select Id from ServiceContract where AccountId = :c.AccountId and Primary_Service_Contract__c = True limit 1].id;
}catch(QueryException e) {
//No records found. Maybe you should set it to Null
}
}
}
}
}
Is there a trigger log
Please find the below modified trigger:
Here I covered:
(1) Added few comments.
(2) Replaced the RecordType Query with Scema object.
(3) Followed the proper naming convention.
(4) Proper Alignment.
(5) Bulkified the trigger.
What you need to do is:
(1) Change the record type name.
(2) Make sure that the API names of Objects and Fields are proper.
(3) Also clarify the requirement, whether we have to do this as part of Insert only or update also.
Please do let me know if it helps you.
Regards,
Mahesh
All Answers
1) Hard code ID
2) SOQL inside for loop
Try to change your code like below Please check below post to learn about trigger best pratice . I hope that will help you
1) http://amitsalesforce.blogspot.com/2015/06/trigger-best-practices-sample-trigger.html
Let us know if this will help you
Thanks
Amit Chaudhary
Please find the below modified trigger:
Here I covered:
(1) Added few comments.
(2) Replaced the RecordType Query with Scema object.
(3) Followed the proper naming convention.
(4) Proper Alignment.
(5) Bulkified the trigger.
What you need to do is:
(1) Change the record type name.
(2) Make sure that the API names of Objects and Fields are proper.
(3) Also clarify the requirement, whether we have to do this as part of Insert only or update also.
Please do let me know if it helps you.
Regards,
Mahesh
1) Hard code ID
2) SOQL inside for loop
Try to change your code like below . I did minor change in below triger
NOTE:- Code i created on notepad. you may get some syntex issue
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
Did you try the code which I posted?
What is the issue you are facing?
Regards,
Mahesh
Please do let us know what is your actual requirement and possible scenarios so that we can help you.
Regards,
Mahesh