You need to sign in to do that
Don't have an account?
Nagma Khan
Calculate the Total Opportunity Amount for the Associated Contact Record
hi
i am new please tell me
how to create sum of the all opportunity amount which is associated with the Contact record on the contact object
Thanks
Nagma Khan
i am new please tell me
how to create sum of the all opportunity amount which is associated with the Contact record on the contact object
Thanks
Nagma Khan
Please find the working code for the above requirement. Hope this helps.
Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering similar issue.
Best Regards,
Nagendra.
All Answers
There is no direct relationship between contact and opportunity so you need to write trigger for that and update field on contact.
please follow the steps :-
1) created field sumOfOpp__c : type number on contact
2) Create Trigger on opportunity;
3)
List<Contact> lstContact = new List<Contact>();
AggregateResult[] groupedResults = [SELECT Id, Sum(Amount) FROM Opportunity GROUP BY ContactId ];
for (AggregateResult ar : groupedResults) {
Contact cont = new Contact();
cont.Id = Id of your contact;
cont.sumOfOpp__c = ar.get('expr0');
lstContact.add(cont);
}
Database.update(lstContact);
Please find the working code for the above requirement. Hope this helps.
Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering similar issue.
Best Regards,
Nagendra.
Nagendra