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
RudiHulsbosRudiHulsbos 

How to insert a AccountSharing record linked to a Territory

Hi All,

 

We need to add a manual AccountSharing records for Territories. We need to manage this process manually and cannot use the standard Territory functionality. In my trigger i have the following steps:

 

 

  • Get the account id
  • Get the territory id
  • Get the group id for the territory
  • Build a list of AccountSharing records to be inserted
The trigger saves correctly, but when i try to insert an account i get the following error:
REQUIRED_FIELD_MISSING, missing required field: AccountAccessLevel (Access level should not be specified on territory manual assignment): [AccountAccessLevel]:
Here is the final insert list code example:
for(ID tid : territoryids){
insert_account_territories.add(New AccountShare(
AccountId = accid,
UserOrGroupId = tid,
AccountAccessLevel = 'Read'));
}

 

Please help!!!!
Thanks,
Rudi

 

MyGodItsColdMyGodItsCold

I did something similar, then added this line:

 

 Database.SaveResult[] lsr = Database.insert(corrShrs,false);

 

where corrShrs are the Share Record list (array). Also, I included a "RowCause" - which I had to define before I executed the code. Check it out in the APEX manual.