+ Start a Discussion
Surinder Singh 25Surinder Singh 25 

Account plan apex sharing issue

trigger UpdTeamMember on Account_Plan_Team_Member__c (before insert, before update, after update) {


Public string level;

list<account_plan__share> sharerec = new list<account_plan__share>();

list<account_plan_team_member__c> members = new list<account_plan_team_member__c> ();
members.add(trigger.new[0]);

if(trigger.isbefore && trigger.isupdate) 
{
 if(trigger.old[0].ap_access__c <> trigger.new[0].ap_access__c) 
{
    id userid = trigger.new[0].siemens_user__c;
    id parentid = trigger.new[0].account_plan__c;

      for(account_plan__share share : [select accesslevel from account_plan__share where userorgroupid=:userid and parentid=:parentid]) 
      {
        level = trigger.new[0].AP_access__c;
        if(level=='Read Only') {share.accesslevel = 'Read';}
        if(level=='Read / Write') {share.accesslevel = 'Edit';}

        sharerec.add(share);
      }
       update sharerec;
}
}

if(trigger.isbefore && trigger.isinsert) 
{
    id userid = trigger.new[0].siemens_user__c;
    id parentid = trigger.new[0].account_plan__c;

      for(account_plan__share share : [select accesslevel from account_plan__share where userorgroupid=:userid and parentid=:parentid])
      {
        level = trigger.new[0].AP_access__c;
        if(level=='Read Only') {share.accesslevel = 'Read';}
        if(level=='Read / Write') {share.accesslevel = 'Edit';}
         system.debug('---' + share.userorgroupid);

        sharerec.add(share);
       }

   insert sharerec;
}
} // end of trigger
Surinder Singh 25Surinder Singh 25
This trigger on Account plan team member and not working. 

When new account team member is added to account plan it should have access autometically . But this trigger doesnt seems to work. 

Please let me know if anythng is wrong in trigger.

Thanks,
Surinder
Ahmad J. KoubeissyAhmad J. Koubeissy
what is the reult of : system.debug('---' + share.userorgroupid); ??