You need to sign in to do that
Don't have an account?
Rachel Linder 8
How can i count the number of opportunity team members
Hello,
I need a way to create a field on the opporutnity level that looks at the opportunity team members and counts of there are or are not any team members. I can't do this via a rollup field. I tried a formula field but can't find a way to get to the opportunity team level.
Any suggestions?
Thank you.
You can write trigger and use aggregate query to count the number of opportunity team member and update the field of opportunity.
https://showbox.onl/ (https://vidmate.onl/)
hope this helps,
Use process builder to call the apex class and update the field on the opportunity, make use of the below query to update the field,
FYI : Update opportunity only when there is a change in the TeamMember size.
Integer x = select Count() from OpportunityTeamMember where OpportunityId = 'OppId', make sure if you are querying using dev console, don't forget to uncheck "USE Tooling API"
Thank You,
Rajesh.
Andrew Fawcett has created a generator of trigger (just point-and-click) for this need.
Declarative Rollups for Lookups! Latest Release Version 2.11
Package tp install:
Production URL: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t0N000000IyYr
Sandbox URL: https://test.salesforce.com/packaging/installPackage.apexp?p0=04t0N000000IyYr
https://github.com/afawcett/declarative-lookup-rollup-summaries
1) Create a new number field : TeamMemberCount on Opportunity.
2) Create a new Lookup Rollup Summary field:
3) Activate the generated trigger (important)
4) It is "realtime".
And that's all. The counter will be always up-to-date.
Zero code written by yourself and the generated code is "perfect" ( Andrew Fawcett is well-known for his top level Apex code )
Just re-create the same lookup summary field on each org.
Alain
This trigger generated in your org is very simple (just one line) because all the logic is into the RollupService class which can access the generic Trigger.oldMap, Trigger.newMap of the current changed opportunity (context of the trigger) and will use the List<RollupSummaries.CalculationMode> put into the Lookup Rollup Summary edit page above (dynamic).
https://github.com/afawcett/declarative-lookup-rollup-summaries/blob/master/force-app/main/classes/RollupService.cls
Alain
Where do I click Manage Child Trigger and Try Again.
Alain
Just calling the trigger with update [SELECT Id FROM OpportunityTeamMember]; is not enough (?) even if the trigger is clearly called viewing the log in the developer console but the button "Calculate" works fine.