You need to sign in to do that
Don't have an account?
Sony PSP
Calculate the sum of quantity from product forecast under agreement under project
Hi guys,
hope you can help me.
I have this two fields under Project__C namely as Primary_Solution_Series__cand Secondary_Solution_Series__c and another field wherein results/sum are being put namely as Allocated_OEM_Project_Forecast__c.
the scenario is I have a product forecast under agreement which is under project meaning the product forecast is the grand child of project.
under the productforecast there are fields namely Quantity and Product(Primary and Secondary Series)
example is below
what i want is that if S332U if chosen as Primary_Solution_Series__c it will auto recalculate having the sum 13000 in the Allocated_OEM_Project_Forecast__c under the Project__c and if Primary_Solution_Series__c is has chosen S3320 it will recalculate having the sum 8500.
another what is the sum of the Allocated_OEM_Project_Forecast__c will also be written on Agreement__c under the field OPA_Lifetime_Product_Forecast__c. wherein the Agreement__c is the child or Project__c
I already have the delete/add function my problem is that when Primary_Solution_Series__c and Secondary_Solution_Series__c has changed it doesn't recalculate.
hope you can help me.
I have this two fields under Project__C namely as Primary_Solution_Series__cand Secondary_Solution_Series__c and another field wherein results/sum are being put namely as Allocated_OEM_Project_Forecast__c.
the scenario is I have a product forecast under agreement which is under project meaning the product forecast is the grand child of project.
under the productforecast there are fields namely Quantity and Product(Primary and Secondary Series)
example is below
what i want is that if S332U if chosen as Primary_Solution_Series__c it will auto recalculate having the sum 13000 in the Allocated_OEM_Project_Forecast__c under the Project__c and if Primary_Solution_Series__c is has chosen S3320 it will recalculate having the sum 8500.
another what is the sum of the Allocated_OEM_Project_Forecast__c will also be written on Agreement__c under the field OPA_Lifetime_Product_Forecast__c. wherein the Agreement__c is the child or Project__c
I already have the delete/add function my problem is that when Primary_Solution_Series__c and Secondary_Solution_Series__c has changed it doesn't recalculate.
Set<ID> poemId = new Set<ID>(); Set<ID> poemssId = new Set<ID>(); Set<ID> pmmfId = new Set<ID>(); List<Apttus__APTS_Agreement__c> AgreementToUpdate = new List<Apttus__APTS_Agreement__c>(); List<Project__c> PaneltoUpdate = new List<Project__c>(); Double pfSum = 0; for(Project__c pfc: newProject){ poemId.add(pfc.id); poemssId.add(pfc.Primary_Solution_Series__c); pmmfId.add(pfc.Secondary_Solution_Series__c);} for(Apttus__APTS_Agreement__c agr : [select id FROM Apttus__APTS_Agreement__c where Panel__c =: poemId]){ poemId.add(agr.id); for(APTS_Product_Forecast__c pf : [SELECT APTS_Quantity__c , APTS_Price_Agreement__c, Panel__c FROM APTS_Product_Forecast__c WHERE (product_is_primary__c = TRUE OR product_is_secondary__c = TRUE ) AND APTS_Price_Agreement__c != NULL AND APTS_Price_Agreement__c =: poemId]){ pfSum +=pf.APTS_Quantity__c; for(Project__c prj: [Select Id, Primary_Solution_Series__c, Secondary_Solution_Series__c from Project__c where Id =: poemId]){ if(prj.Primary_Solution_Series__c != oldMap.get(prj.id).Primary_Solution_Series__c || prj.Secondary_Solution_Series__c != oldMap.get(prj.id).Secondary_Solution_Series__c) prj.Allocated_OEM_Project_Forecast__c = pfSum; PaneltoUpdate.add(prj); } for(Apttus__APTS_Agreement__c agmt: [Select Id from Apttus__APTS_Agreement__c where ID =: poemId]){ agmt.OPA_Lifetime_Product_Forecast__c = pfSum; AgreementToUpdate.add(agmt);} }
Have u added debug statement to see the sum of quantity.
I am also new to Apex and the below code may not be the correct solution, but I hope it can be of some help in terms of rewritting the logic,
thanks for this, I was also able to figure it out before this post and its a bit same :) thanks men :)