function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
❤Code❤Code 

Calculate no of contact roles on opportunity

Hi All,

Can anyone let me know how to calculate no of contact roles on opportunity.

Regards
sandeep reddy 37sandeep reddy 37
use  aggrate function 
you will get it
 
Vijay NagarathinamVijay Nagarathinam
Hi,

Refer the below blog you get some idea about your task,

http://www.oyecode.com/2012/01/salesforce-trigger-to-count-contact.html
http://salesforce.stackexchange.com/questions/25622/trigger-that-counts-how-many-contact-roles-have-a-specific-role-on-an-opportunit

Thanks,
Vijay
❤Code❤Code
Hi Vijay,

I am having issue in the below link for below code - 

http://www.oyecode.com/2012/01/salesforce-trigger-to-count-contact.html

Code - 
List<OpportunityContactRole> oContactRoles = new List<OpportunityContactRole>(contactRoleMap.get(oppy.id));    
           
        if(oContactRoles!=NULL && !oContactRoles.isempty()){ 
            oppy.ContactRoleCount__c = oContactRoles.size();                                                                                      //return the map size
        }

I am getting oppy variable undefined. Can u check and let me know how to resolve the issue.

Regards