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
Harshada Kadu 9Harshada Kadu 9 

Account: insufficient access rights on cross-reference id

Hi ,
I have integration from a site named SEA to salesforce.
I have used account object to create accounts of customer. There are fields which get updated from sea to salesforce.
In Account object, there are two fields which have lookup given to user. The fields are owner(standard field) and owner1__c(custom field).
Now when account gets created in Sea the data gets pushed in salesforce properly. The problem arises when owner or owner1__c are changed in Sea. These changes don't reflect in Salesforce. Instead error arises  saying :-

Account {"Party_Sea_ID__c":8590,"Customer_Number__c":"C3235","Name":"Testing Sales Force ","DBA_Name__c":"Testing Sales Force ","OwnerId":"00528000005HQRPAA4","owner1__c":"00528000005HQRUAA4","Default_Currency__c":"US DOLLARS","Industry":"Jewelry","Business_Type__c":"JEWELLERY","No_of_Doors__c":4,"NumberOfEmployees":6,"Store_Size__c":6543,"Contact_Person__c":"Oliver","Rolex_Dealer__c":"Yes","Status__c":0,"Territory__c":"NYC","Sales_Code__c":"ASSET AND MEMO","RecordTypeId":"01228000000QbiM","Asset_Credit_Limit__c":0,"Memo_Credit_Limit__c":0,"Outstanding_A_R_Balance__c":0,"Outstanding_Memo_Balance__c":0,"BillingStreet":"101 Beckhem Drive,Lane Street,NEW YORK - 12345 , NEW YORK , USA","BillingCity":"NEW YORK","BillingState":"NEW YORK","BillingCountry":"USA","BillingPostalCode":"12345","Phone":"1234567890","Email__c":"Noemail@email.com"} insufficient access rights on cross-reference id: 00528000005HQ
-----------------------------------------------------------------------------------------------------
I have written two triggers: 

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('************* Salesforce Account ID ******* '+a.Id);
   
   accountRecord.UserOrGroupId = a.owner1__c;
   System.Debug('************* Salesforce Custom Owner: Account Executive ******* '+ a.owner1__c);
    
  
   accountRecord.AccountAccessLevel= 'edit';
   System.debug('Account Acess: '+  accountRecord.AccountAccessLevel);
   
   accountRecord.OpportunityAccessLevel='Read';
   System.debug('Opportunity Acess: '+  accountRecord.OpportunityAccessLevel);
   
   System.debug('Acc_share_trigger Account Record: '+ accountRecord);
    
   jobShares.add(accountRecord);
   }  

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

trigger Delete_Share on Account (after update) {
    
      // get the id for the group for everyone in the org
  ID groupId = [select id from Group where Type = 'Organization'].id;
  System.debug('Group ID:'+groupId);

    if(Trigger.isUpdate) {

    List<AccountShare> sharesToCreate = new List<AccountShare>();
    List<ID> shareIdsToDelete = new List<ID>();
    
    for (Account acc : Trigger.new) {
        shareIdsToDelete.add(acc.id);
        System.debug('Delete Account Share ID:'+acc.id);

      }
       
    // do the DML to delete shares
        if (!shareIdsToDelete.isEmpty())
         delete [select id from AccountShare where AccountId IN :shareIdsToDelete and RowCause = 'Manual'];
        System.debug('Deleted successfully..');

    /*// do the DML to create shares
    if(!sharesToCreate.isEmpty())
    insert sharesToCreate;
    System.debug('Create Share:'+sharesToCreate);*/
    }

}

----------------------------------------------------------------------------------------------
What to change in triggers to get fields updated in salesforce.?

Regards,
Harshada Kadu
 
PawanKumarPawanKumar
Hi Harshada,
You just need to give READ access for object USER in your profle associated with your integration user.

Note : 00528000005HQ - Here 005 means USER object.

Regards,
Pawan Kumar