You need to sign in to do that
Don't have an account?
Deepak Pandey 13
trigger to update cutom field user insert accountteammember
trigger to insert and update cutom field user on account .
1- insert time hard coded value fill in accountteammember.
2-update time user (look up of user) change than accountteammember user will be same.
trigger-
trigger atm on account(after insert,after update)
{
list<AccountTeamMember> accountTeamList=new list<AccountTeamMember>();
if(Trigger.isInsert)
for(account a:trigger.new)
{
AccountTeamMember acctTM = new AccountTeamMember();
AccountShare acctShare = new AccountShare();
acctTM.AccountId = a.id;
acctTM.userId = a.user__c;
acctTM.TeamMemberRole = 'Account Manager';
accountTeamList.add(acctTM);
}
for(account acc:trigger.new)
{
Account oldAccount = Trigger.oldMap.get(acc.ID);
if(acc.user__c != oldAccount.user__c)
{
AccountTeamMember acctTM = new AccountTeamMember();
AccountShare acctShare = new AccountShare();
acctTM.AccountId = acc.id;
acctTM.userId = acc.user__c;
//acctTM.TeamMemberRole = 'Account Manager';
accountTeamList.add(acctTM);
}
}
insert accountTeamList;
}
1- insert time hard coded value fill in accountteammember.
2-update time user (look up of user) change than accountteammember user will be same.
trigger-
trigger atm on account(after insert,after update)
{
list<AccountTeamMember> accountTeamList=new list<AccountTeamMember>();
if(Trigger.isInsert)
for(account a:trigger.new)
{
AccountTeamMember acctTM = new AccountTeamMember();
AccountShare acctShare = new AccountShare();
acctTM.AccountId = a.id;
acctTM.userId = a.user__c;
acctTM.TeamMemberRole = 'Account Manager';
accountTeamList.add(acctTM);
}
for(account acc:trigger.new)
{
Account oldAccount = Trigger.oldMap.get(acc.ID);
if(acc.user__c != oldAccount.user__c)
{
AccountTeamMember acctTM = new AccountTeamMember();
AccountShare acctShare = new AccountShare();
acctTM.AccountId = acc.id;
acctTM.userId = acc.user__c;
//acctTM.TeamMemberRole = 'Account Manager';
accountTeamList.add(acctTM);
}
}
insert accountTeamList;
}
Can you explain your requirment clearly ? So that we can help you .
.
Try with below code it wil help !!
Let me know if it helps !!!
Thanks
Mnaoj
Nothing is there in line 28 ,is is it possible to share your debug log ?
Account teamMember userId field is is readonly .So you can try like below .
Let me know if it works or still issue .
Thanks
Manoj
Check with your team ,whether you want to delete the previous TeamMember of you want to keep it .
delete accTmLst;
}catch(DmlException ex){
System.debug(ex);
}...not working
accountteammember not ceated !