You need to sign in to do that
Don't have an account?

Code clarify
hi
I want to execute the below code if VPA(custom field on Account of type checkbox) is true
trigger AccountTeam on Account (before insert,after update) {
if(trigger.isafter && Account.VPA__c!=null)
{
Integer newcnt=0;
Integer newcnt0=0;
AccountTeamMember[] newmembers = new AccountTeamMember[]{};
//list of new team members to add
AccountShare[] newShare = new AccountShare[]{};
//list of new shares to add
Account a1 = [select id, parent.Id,OwnerId from account Where Id=:trigger.new[0].ParentID];
ID uid = a1.OwnerId;
//get the user id of the parent Account, anyone that changes the Account will added to the account team
for(Account a:trigger.new)
{
AccountTeamMember Teammemberad=new AccountTeamMember();
Teammemberad.AccountId=a.id;
Teammemberad.UserId=uid;
Teammemberad.TeamMemberRole = 'Account Modifier';
newmembers.add(Teammemberad);
}
Database.SaveResult[] lsr = Database.insert(newmembers,false);
//insert any valid members then add their share entry if they were successfully added Integer newcnt=0;
for(Database.SaveResult sr:lsr)
{
if(!sr.isSuccess())
{
Database.Error emsg =sr.getErrors()[0];
system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg);
}
else
{
newShare.add(new AccountShare(UserOrGroupId=newmembers[newcnt].UserId, AccountId=newmembers[newcnt].Accountid, AccountAccessLevel='Read',OpportunityAccessLevel='Read'));
}
newcnt++;
}
Database.SaveResult[] lsr0 =Database.insert(newShare,false);
//insert the new shares Integer newcnt0=0;
for(Database.SaveResult sr0:lsr0)
{
if(!sr0.isSuccess())
{
Database.Error emsg0=sr0.getErrors()[0];
system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0); } newcnt0++; }
}
}
But this is executing though VPA==null.
Quick response highly appriciated
Hi,
Could you please try below code:-
Problem was with you were not trying to access a record, but a field.
Let me know if you have any question.
Happy to help you!
All Answers
Hi,
Can you please verify data type of VPA?
Data type is checkbox
Hi,
What error it gives you if you try below code in if?
Hi,
Could you please try below code:-
Problem was with you were not trying to access a record, but a field.
Let me know if you have any question.
Happy to help you!
Happy that it worked for you! Could you please give me a KUDOS, if you think that I was able to help you.