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
sfdcChi2sfdcChi2 

I need to write the name of a member in an opportunity team on a field in opportunity based on the teamrole of the member. I am new to apex and would appreciate a code snippet that can do this. thanks

Best Answer chosen by sfdcChi2
sfdcChi2sfdcChi2
Would appreciate if you could help with the bulkifying the below trigger. thanks.


trigger SSSUpdate on User (before Update)
{

For (User u1 : Trigger.New)
{
UserTeamMember u =  [SELECT UserId, User.Name FROM UserTeamMember where TeamMemberRole= 'Sales Support Specialist' 
AND OwnerId=:u1.ID];

u1.SSS__c= u.UserId;
}
}

All Answers

vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
When you need this to happen? while adding team members?
sfdcChi2sfdcChi2
Yes! while adding members to the default team
vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
Unfortunately, triggers or workflow rules doesnt fire while adding members to the default team.

http://help.salesforce.com/HTViewSolution?id=000187820&language=en_US
sfdcChi2sfdcChi2
Thank you for the information. Appreciate your time!
sfdcChi2sfdcChi2
Would appreciate if you could help with the bulkifying the below trigger. thanks.


trigger SSSUpdate on User (before Update)
{

For (User u1 : Trigger.New)
{
UserTeamMember u =  [SELECT UserId, User.Name FROM UserTeamMember where TeamMemberRole= 'Sales Support Specialist' 
AND OwnerId=:u1.ID];

u1.SSS__c= u.UserId;
}
}
This was selected as the best answer