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
sainath reddy 54sainath reddy 54 

Hi guys, someone help me here with this scenario: When a new Case is created with case origin as Web then add the user karthic as CaseTeamMember

Unable to create a new case member here:
public class opportunityteammembertask {
    public static void teamopptyt(list<opportunity> oppty){
        user u =[select id from user where alias =: 'sai'];
        list<opportunityteammember> opptyteam = new list<opportunityteammember>();
        for(opportunity op:oppty)
        {
            if(op.Amount >= 5000000){
                opportunityteammember tm = new opportunityteammember();
                tm.OpportunityId =op.id;
                tm.UserId=u.id;
                tm.TeamMemberRole='Channel Manager';
                //tm.OpportunityAccessLevel='Read/Write';
                   opptyteam.add(tm); 
            }
        } if(opptyteam.size() > 0){
            insert opptyteam;
        }
    }
}
PriyaPriya (Salesforce Developers) 
Hi Sainath,

Can you please try writing trigger on case with the check of web origin and 
and add the team member

Refer below sample code written on Account :- 
trigger IT_atm on Account (after insert) {
list<AccountTeamMember> atm1=new list<AccountTeamMember>();
user u=[select name from user where alias='rpa'];
for(account a:trigger.new){
if(a.AnnualRevenue>500000){
AccountTeamMember atm=new AccountTeamMember();
atm.userid=u.id;
atm.AccountId=a.id;
atm.TeamMemberRole='Lead Qualifier';
atm.AccountAccessLevel='All';
atm1.add(atm);
}
}
insert atm1;
}



Regards,
Ranjan