Skip to main content
Hi Guys,

I have a custom object "Account_Team_Relationship__c" which is related to standard object Account.

Wheneever user is creating new Account_Team_Relationship__c object record, User details (Name, Account Access, Contact Access, Opportunity Access, Case Access and role) should be automaticaly saved to Account Team members, if the user details are not available in Account team members.

As of now Team role can be hardcoded.

Is it possible to do this with trigger?

Your thoughts are highly appreciated.
6 answers
  1. Jun 28, 2018, 8:18 AM

    trigger AccountTeamChanges on Account_Team_Relationship__c (after insert) {

    List<AccountTeamMember> acctMembers = new List<AccountTeamMember>();

    List<AccountShare> acctSharingRules = new List<AccountShare>();

    for(Account_Team_Relationship__c a : Trigger.new)

    {

    if(Trigger.isInsert)

    {

    AccountTeamMember ca = new AccountTeamMember();

    ca.AccountId = a.Id;

    ca.TeamMemberRole = 'xxxxx';

    acctMembers.add(ca);

    insert acctMembers;

    AccountShare caSharingRule = new AccountShare();

    caSharingRule.AccountId = a.Id;

    caSharingRule.OpportunityAccessLevel = 'Read';

    caSharingRule.CaseAccessLevel = 'Read';

    caSharingRule.AccountAccessLevel = 'Edit';

    acctSharingRules.add(caSharingRule);

    insert acctSharingRules ;

    }

    }}

     
0/9000