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
tomasddtomasdd 

Trigger for checking if user exist in Opportunity Team

Hi All, 

Please help - I have to build a trigger which will check if I want to add user A and this user is existing in Opportunity Team already show error "User already exist in Opportunity Team ! Add another user".

 

Thank you for help

 

 

ANUTEJANUTEJ (Salesforce Developers) 
Hi Tomas,

This is just a way I could think but I think what you could do is to get all the opportunity teams that the user belongs and in case if the user is present in the opportunity team then you could throw an error.

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
tomasddtomasdd

Hi Anutej,

This is good idea but if you have a 2 opportunities "OppA" and "OppB" and user exist only in opportunity team for opportunity "OppA" then you will be able to add the same user for opportunity team for "OppB" but for "OppA" not. 

 

This is why I need a trigger to check if user is exist on opportunity team for current opportunity.

ANUTEJANUTEJ (Salesforce Developers) 
please correct me if I am wrong but according to my understanding you want a trigger such that if a user is present in one opportunity team then he should not be added to the same opportunity team if this is right then I think you should be able to achieve this with the above way.

Hope I was able to address in case if there is any difference in understanding please let me know.
tomasddtomasdd

Not exactly, 

Let's imagine that you have 2 opportunities A and B for example. These opportunites have opportunity teams. Now you can add User ABC to opp team in opportunity A and B. You added this user to opp team for opportunity A.

But when another user would like to add the same user ABC to opportunity team for opportunity A he should see the error "Hey, the user is already exist".  

ANUTEJANUTEJ (Salesforce Developers) 
Apologies, I was responding to a different question.

This is just an idea but would it be possible to have a field that could hold all the opportunity teams a user belongs to and in case if a user is trying to add a particular user to an opportunity team you can check with the values in that custom field and in case if he is already present you could certainly throw an error.