You need to sign in to do that
Don't have an account?
3C
Custom Roll-Up Summary trigger of Contract on Account
I am trying to implement a roll-up summary of the earliest contract start date on the account object using the code outlined here (http://blog.elieperez.net/salesforce-lookup-roll-up-summary/). Below is my trigger.
This gives me the error:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger rollupContractsOnAccount caused an unexpected exception, contact your administrator: rollupContractsOnAccount: execution of AfterInsert caused by: System.SObjectException: Invalid field Account for Contract: Class.LookupCalculation.Calculate: line 25, column 1
What am I missing? The error is on "myparentfield," which is correct as Account for the Contract object.
trigger rollupContractsOnAccount on Contract (after insert,after update,after delete,after undelete) { string mysobjectParent = 'Account', // Parent sobject API Name myrelationName = 'Contract__r', // Api name of the relation between parent and child (ends with __r) myformulaParent = 'Customer_Since__c', // Api name of the number field that will contain the calculation mysobjectChild = 'Contract', // Child sobject API Name myparentfield = 'Account', // Api name of the lookup field on chield object myfieldChild = 'Subscription_Start_Date__c'; // Api name of the child field to roll up LookupCalculation.Method method = LookupCalculation.Method.MIN; //Selected method: could be COUNT, SUM, MIN, MAX, AVG LookupCalculation calculation = new LookupCalculation(mysobjectParent, myrelationName, myformulaParent, mysobjectChild, myparentfield, myfieldChild); List<sobject> objList = new List<sobject>((List<sobject>) Trigger.new); if(Trigger.isDelete) objList = Trigger.old; if(Trigger.isUpdate) objList.addAll((List<sobject>) Trigger.old); calculation.calculate(method, objList); }
This gives me the error:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger rollupContractsOnAccount caused an unexpected exception, contact your administrator: rollupContractsOnAccount: execution of AfterInsert caused by: System.SObjectException: Invalid field Account for Contract: Class.LookupCalculation.Calculate: line 25, column 1
What am I missing? The error is on "myparentfield," which is correct as Account for the Contract object.
Saikishore Reddy Aengareddy
I think the API name is AccountId, Update it to AccountId and see if it solves the problem.
3C
Thanks. Unfortunately it now times out when I try to add a new contract record. How could I make it more efficient?