You need to sign in to do that
Don't have an account?
Sony PSP
Trigger, Sum on a Field
Hi Guys,
Can you help me with this, I am just new with salesforce
I need to update the Project Object where the field is OEM_Project_Forecast__c, the Agreement__c is the child of the Project, and the Child of Agreement are list of Product_Forecast__cwherein I need to get the sum of all the product forecast and put it on the Project under the OEM_Project_Forecast__c the sum of product forecast.
thank you
Can you help me with this, I am just new with salesforce
I need to update the Project Object where the field is OEM_Project_Forecast__c, the Agreement__c is the child of the Project, and the Child of Agreement are list of Product_Forecast__cwherein I need to get the sum of all the product forecast and put it on the Project under the OEM_Project_Forecast__c the sum of product forecast.
thank you
public with sharing class AgreementTriggerHandler{ public static void onAfterInsert(List<Agreement__c> agrList) { isUpdateSynapticsPanel(agrList); } public static void onAfterUpdate(List< Agreement__c> agrList) { isUpdateSynapticsPanel(agrList); } public static void isUpdateSynapticsPanel (List< Agreement__c> agrList){ Set<Id> agrIdSet = new Set<Id>(); List<Project__c> PaneltoUpdate = new List<Project__c>(); Double pfSum = 0; for(Agreement__c pfs : agrList){ // if(pfs.Panel__c != null) System.debug('PFA value = ' + pfs); agrIdSet.add(pfs.Panel__c); } //System.debug('agrIdSet value = ' + agrIdSet); for(Agreement__c pf: [SELECT Lifetime_Product_Forecast__c, Panel__c FROM Agreement__c WHERE Panel__c =: agrIdSet]){ System.debug('pf value = ' + pf); pfSum += pf.Lifetime_Product_Forecast__c; } for(Project__c prj: [Select Id from Project__c where Id =: agrIdSet]){ System.debug('projsum value = ' + prj); prj. OEM_Project_Forecast__c = pfSum; System.debug('SUM value = ' + pfSum); PaneltoUpdate.add(prj); } if(!PaneltoUpdate.isEmpty()){ update PaneltoUpdate; } } }
could you tell me more clearly what issue are you facing? The code looks fine, it would update all the prj.OEM_Project_Forecast__c with the same sum value pfSum you have generated
Thanks and Regards,
Shiva RV
in "where Id =:"
shouldn't it be "IN"?
Good Luck!