You need to sign in to do that
Don't have an account?

Rollup summary on lookup Relationship
-----Rollup Summary of Lookup Relationship-------------------------
Hi All,
I want to create a Rollup field in Account Object with Custom Object called 'Contact Partner'.
'Contact Partner' Object is maintaining a lookup relationship with Account Object.
I want to fill the Rollup field with name 'Total Revenue' in Account object, which should tell the total amount of Revenue generated by each Contact Partner.
Each 'Contact Partner' would be maintaining the field called 'Revenue Generated'.
For Ex
Account A has three Contact Partner(CP) and each CP is generating revenue of 10$,20$ & 30$. Hence the field 'Total Revenue' in Account object should automatically fill with '60$'
Can anyone help me on this along with the Code?, Actually I'm new on the trigger.
Please check once below code below code will count number of contacts on account object.
http://salesforceprasad.blogspot.in/2017/12/roll-up-summary-functionality-through.html#gpluscomments
For your requirement please change code like below.
public integer double totalAmount;
for(account acc : lstAccs){
system.debug('==acc.contacts.size()=='+acc.contacts.size());
for(contact con = acc.contacts){
totalAmount = con.amount__c;
}
acc.totalAmountofcon__c = totalAmount;
updLstOfAccs.add(acc);
}
if(updLstOfAccs.size() > 0){
update updLstOfAccs;
}
Hope it helps you.
if it helps you please mark it as best answer.
Please let me know incase of any other help.
Thanks
Varaprasad
totalAmount = con.amount__c;
}
Hi Varaprasad,
Thanks for your quick response.
I have written the below class by changing the code which you have shared. But i am getting the below error. The error looks like that i haven't written the correct SOQL. Can you please help me here?
FYR.....
Parent Object -->Customer_Outlet__c
Child Object-->Contact_Partner__c
Relationshop is look up
1)Customer_Outlet__c has field 'Total_CP_Salary__c '
2)Contact_Partner__c has field 'Salary__c '
My objective is to fill 'Total_CP_Salary__c' field automatically, which is the summation of 'Salary__c ' of each Contact_Partner__c under Customer_Outlet__c .
Can you please help me to achieve this?
Regards,
Varun
Please try once below code :
Hope it will help you.
Thanks
Varaprasad
I am still getting the below error.
Code Written:-
Please check once child object relationship name of Contact_Partner__r in the child object.
Then use child relationship name on a query.
Example like below :
http://raydehler.com/cloud/clod/salesforce-soql-subquery-and-custom-objects-with-apex.html\
Then use like below query :
Select Name, (Select Name from ObjectDetails__r) From ObjectMaster__c
Hope this helps.
Thanks
Varaprasad
use above query i think yourchildrelationshipname is : Contact_Partners
I am able to save the class now. The mistake is shown below:
Instead of 'Contact_Partners__r' we were putting 'Contact_Partner__r'.
list<Customer_Outlet__c> lstAccs = [select id,Total_CP_Salary__c,(select id,Salary__c from Contact_Partners__r) from Customer_Outlet__c where id in : accIds];
I observed that the output is not accurate. Please have a look.
use below line instead of above line.
public integer totalAmount = 0;
Thanks
Varaprasad
Please add below lineinsted of totalAmount = cpr.Salary__c
totalAmount = totalAmount + cpr.Salary__c;
Thanks
Varaprasad
It worked.!!!
I need one help and Suggestion. Can this be created using Map<id,list<Contact>> instead of using the only List?
If yes, can you please share the Code?
Regards,
Varun
Can anyone please help me here?
If I want to perform this operation using Map. Can we do it?
If yes, please can you help me with a code?
Regards,
Varun