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
Shyam Sundar 84Shyam Sundar 84 

Help me on account share trigger


trigger AccountTrigger on Account (after insert, after update) {


    for(Account acc : Trigger.new){

accountShare as1=[SELECT id, AccountaccessLevel,RowCause,userorgroupid from accountShare where accountid=:acc.id and rowcause='Rule'];

        AccountShare accountShare = new AccountShare();
        accountshare.RowCause='Rule';  
     //   userorgroupid =''
        accountShare.AccountAccessLevel = 'All';
        update accountshare; 
    }

 

   

}
Iram MalikIram Malik
what is the issue you are facing? Your RowCause has value as Rule. You can update only share records which have RowCause value as 'Manual'. May be if you can share the issue, we can help.
karthikeyan perumalkarthikeyan perumal
Hello, 

What is the actual issue in this?.. can you expline me for further debug

Thanks
karthik
Raj VakatiRaj Vakati
You can try to do like this 

Row Casuse can be Owner, Manual etc 

 
trigger CheckRowcause on Account (after insert) {
    List<AccountShare> shares = new List<AccountShare>();
          User u = [Select id from user where Id =:'00528000000c7WG'];
    for(Account a : Trigger.new){
    
          AccountShare aShare           = new AccountShare();
          aShare.AccountId              = a.Id;
          aShare.UserOrGroupId          = u.Id;
          aShare.RowCause =Schema.Accountshare.RowCause.owner;
          aShare.AccountAccessLevel     = 'Edit';
          aShare.OpportunityAccessLevel = 'Edit';
          shares.add(aShare);
    }
insert shares;
}