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
sfdeveloper12sfdeveloper12 

Custom Account Sharing is not working for freeze user

Hello, 

I have written trigger where i have created custom field which has lookup to user. I am using standard owner field as well as custom field both are lookup to user. The thing is i am transferring all the data from SEA to Salesforce. SEA is integrated with salesforce. Account sharing is working well on salesforce but not when owner is changed from SEA. I am not getting exact solution to recover this issue. This problem is for one of the user which is deactivated from salesforce. So is it possible that trigger wont work for deactivated user ? but if i make changes from salesforce org then it works fine. 

My trigger is as below and i dont feel there is any problem in trigger.

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

 List<AccountShare> jobShares = new List<AccountShare>();
    
 for(Account a : trigger.new){

if (a.owner1__c != null) {
 
   

   AccountShare accountRecord = new AccountShare();
   accountRecord.AccountId= a.Id;
    
   
   System.Debug('************* Account ID ******* '+a.Id);
   accountRecord.UserOrGroupId = a.owner1__c;
   System.Debug('************* Account ID ******* '+ a.owner1__c);
    
  
   accountRecord.AccountAccessLevel= 'edit';
   accountRecord.OpportunityAccessLevel='Read';
  System.debug('Acc_share_trigger Account Record: '+ accountRecord);
    
    
 // studentRecord.RowCause = Schema.Test_Share.RowCause.Student_Access__c;
   jobShares.add(accountRecord);
 }  

 /** Insert all of the newly created Share records and capture save result **/
 Database.SaveResult[] jobShareInsertResult = Database.insert(jobShares,false);

}
}

Thanks & Regards,
Utkarsha