You need to sign in to do that
Don't have an account?
S_Batman
Adding custom field from Contacts and Showing on Accounts
I have a custom number field on the Contact level (let's call it ABC), and I want to create a Field on the Account to show the total of all the ABC fields from all related Contacts to an Account. Can this be done without triggers?
Please check with the below thread from stack exchange community exactly with similar error which has a suggested workaround.
Modify your code as per the requirement which should help you to surpass the above challenge.
- http://salesforce.stackexchange.com/questions/40375/sobject-row-was-retrieved-via-soql-without-querying-the-requested-field
- https://developer.salesforce.com/forums/?id=906F00000008vfYIAQ
Best Regards,Nagendra.P
All Answers
I have modified the above trigger you mentioned to update the Account field with SUM of all its related contact Custom Field. Replace the Field_On_Contact__c with Contact Field API name and Field_On_Account__c with Account Field API name. You can also consider Andrew Fawcett's Declarative Lookup Rollup Summaries app, which is 100% free and can accomplish your goal.
It (just like Rollup Helper), DOES use triggers, but it allows you to create these rollups without advanced trigger knowledge through a pretty simple to use UI within Salesforce
- https://github.com/afawcett/declarative-lookup-rollup-summaries
Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue and becomes a proper solution which results in helping others who are really in need of it.Best Regards,
Nagendra.P
Nagendra:
Thank you but
19Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
20 ,Number_of_Contacts__c
21 from Account
22 where Id in :acctIds]);
The bolded field, should that be removed or replaced with the Field_On_Account__c ?
Yes, give a try by replacing the above field which should suffice your requirement.
Thanks,
Nagendra.P
Thank you I was able to replace it and save it. However, when I update the contact field to test it I am getting the following error:
Error:Apex trigger ContactSumTrigger caused an unexpected exception, contact your administrator: ContactSumTrigger: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Contact.Number__c: ()
Please check with the below thread from stack exchange community exactly with similar error which has a suggested workaround.
Modify your code as per the requirement which should help you to surpass the above challenge.
- http://salesforce.stackexchange.com/questions/40375/sobject-row-was-retrieved-via-soql-without-querying-the-requested-field
- https://developer.salesforce.com/forums/?id=906F00000008vfYIAQ
Best Regards,Nagendra.P