You need to sign in to do that
Don't have an account?
Justin Staugaitis
Apex trigger not summing fields
Im new to APEX and i have a trigger that is suppose to calculate a total score using 6 fields. If any of the data in those 6 fields gets updated I want the Trigger to recalcuate the score. But my current code is not updating. I have two issues
1) After I deployed the code the APEX trigger didnt do the calculation. Why is this?
2) After I made a change to one of the 6 data points the Trigger still didnt execute. Why is this?
Could someone help look at the code I have and provide some recommeneded changes. (just note I am new so some of the terms I may not understand if you would make any code changes can you show me the before and after change).
trigger Health_Score_Calculation_New on Account (before insert) {
if(Trigger.isBefore)
{
if (Trigger.isInsert || Trigger.isUpdate)
{
for(Account cob : trigger.new)
{
if(cob.Days_With_No_Activity__c!=null){
// cob.Days_With_No_Activity__c= 100 ;
cob.Score__c = (cob.Implementation__c * 0.15) +
(cob.Migration_In_Progress__c * 0.20) +
(cob.Days_With_No_Activity__c * 0.15) +
(cob.Contact_New2__c * 0.15) +
(cob.Contact_Left2__c * 0.15) +
(cob.Issues__c * 0.20) ;
}
}
}
}
}
1) After I deployed the code the APEX trigger didnt do the calculation. Why is this?
2) After I made a change to one of the 6 data points the Trigger still didnt execute. Why is this?
Could someone help look at the code I have and provide some recommeneded changes. (just note I am new so some of the terms I may not understand if you would make any code changes can you show me the before and after change).
trigger Health_Score_Calculation_New on Account (before insert) {
if(Trigger.isBefore)
{
if (Trigger.isInsert || Trigger.isUpdate)
{
for(Account cob : trigger.new)
{
if(cob.Days_With_No_Activity__c!=null){
// cob.Days_With_No_Activity__c= 100 ;
cob.Score__c = (cob.Implementation__c * 0.15) +
(cob.Migration_In_Progress__c * 0.20) +
(cob.Days_With_No_Activity__c * 0.15) +
(cob.Contact_New2__c * 0.15) +
(cob.Contact_Left2__c * 0.15) +
(cob.Issues__c * 0.20) ;
}
}
}
}
}
I added (before insert, before update) and that seems to resolve my issue with question 2 but I had to update the record for the change to take affect.
So is there a way i can have all the records update so this trigger populates for all accounts.