You need to sign in to do that
Don't have an account?
rameshvpsg
Roll up opportunity amount to contact roles
Hi, I have an requirement to roll up opportunity amount to all contacts linked through contact roles for an opportunity. Do any one have solution for this.
Thanks,
Ramesh V
Hi
I think you can do throght the workflow rule with FIled Update. Did you try?
i know they are using junction object between Contact and Opp.
Your requirement was a little unclear to me...but if you meant the amount of opportunities rolled up onto the contact record then this accomplishes that.
Here is some sample code to get you started. You will probably want to add an isPrimary Where clause in the subquery in the final for soql loop.
Thanks Andrew. I will try this. I actually wanted to populate total amount that a contact has influenced part of contact layout. For all won opportunities, i wanted to populate the amount from opportunity object to all contacts that are mapped in contact roles.
Hi Andrew, Need a help. I tried using the code you provided after creating custom field "pidm__c" in contact. But while saving the trigger i get below error.
Error: Compile Error: Variable does not exist: pidm__c at line 16 column 9.
Line 16 is : c.pidm__c = c.OpportunityContactRoles.size();
Hi Ramesh,
Andrew created that field.I think you didn't create that field or the name is different. See in your Contact Object.
HI Mahi, i have created the field pidm ("pidm__c") in contact object. But still it gives that error.
See the field name in the Contact object (Speeling).
can you post your code then i can help you out.
Mahi,
Here is the code:
trigger oppContactRoleSize on Opportunity (after update,after insert) {
Set<Id> oppIds = new Set<Id>();
oppIds.addAll(Trigger.newMap.keySet());
Set<Id> contactIds = new Set<Id>();
//grab the contact ids from the oppconrole object
for(OpportunityContactRole o: [SELECT ContactId FROM OpportunityContactRole WHERE OpportunityId IN :oppIds])
contactIds.add(o.ContactId);
List<Contact> consToUpdate = new List<Contact>();
//query contacts and roles and set field to size...you can restrict the query by adding a where clause if needed
for(Contact c : [SELECT Id,(SELECT id FROM OpportunityContactRoles) FROM Contact WHERE ID IN :contactIds]){
//put the name of the field in the below line...i used a field from my org which is pidm__c
c.pidm__c = c.OpportunityContactRoles.size();
consToUpdate.add(c);
}
update consToUpdate;
}
//and the field name in contact object is pidm__c
Hi
Can you try the belwo code.IF it is not working please let me know.
trigger oppContactRoleSize on Opportunity (after update,after insert) {
Set<Id> oppIds = new Set<Id>();
oppIds.addAll(Trigger.newMap.keySet());
Set<Id> contactIds = new Set<Id>();
//grab the contact ids from the oppconrole object
for(OpportunityContactRole o: [SELECT ContactId FROM OpportunityContactRole WHERE OpportunityId IN :oppIds])
contactIds.add(o.ContactId);
List<Contact> consToUpdate = new List<Contact>();
//query contacts and roles and set field to size...you can restrict the query by adding a where clause if needed
for(Contact c : [SELECT Id,pidm__c,(SELECT id FROM OpportunityContactRoles) FROM Contact WHERE ID IN :contactIds]){
//put the name of the field in the below line...i used a field from my org which is pidm__c
c.pidm__c = c.OpportunityContactRoles.size();
consToUpdate.add(c);
}
update consToUpdate;
}
Hi Mahi,
Still i get the same error. Error: Compile Error: Variable does not exist: pidm__c at line 16 column 9
ok, commnet line no 16 and save it if it is giving the same error in line 14 then you can carete one more field and use that field instead of pidm__c.try and let me know
Ok. Now it says Error: Compile Error: Loop variable must be an SObject or list of Contact at line 14 column 17
ok, Create a new variable like pidm1__c use that varaible instead of pidm__c
it gives the same error for new field also.