• MattE
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

Hi,

 

I am a complete newbie to Apex triggers so hopefully someone can help.

 

CURRENT SITUATION:

Each day our SF org auto-imports Account records plus their related Account Team members (added to AccountTeamMember object) from an external source. When each related Account Team member is inserted it also automatically creates a record in the AccountShare table. This table has 3 "AccessLevel" fields that are given the following values:

 - AccountAccessLevel = 'Read'

 - OpportunityAccessLevel = 'None'

 - CaseAccessLevel = 'None'

* Note - These 3 values are set by default from our OWD settings which are Account, Opportunity and Private all = 'Private' and it has to stay this way.

 

PROBLEM:

But I need these 3 fields to have the following values:

 - AccountAccessLevel = 'Edit'

 - OpportunityAccessLevel = 'Read'

 - CaseAccessLevel = Edit'

 

DAILY MANUAL WORK-AROUND:

What I do then each day to fix the problem is export any newly inserted records (via apex data loader) to a CSV file using this query:

 

   Select Id, AccountAccessLevel, OpportunityAccessLevel,

   CaseAccessLevel FROM AccountShare WHERE RowCause in ('Team') AND

   LastModifiedById in ('00590000001CEQQAA4') AND AccountAccessLevel in

   ('Read') AND CaseAccessLevel in ('None') AND OpportunityAccessLevel in ('None')

 

Then I manually change the 3 AccessLevel values in the CSV file to the values that  I need them to be (ie 'Edit' 'Read' 'Edit') and then I update the records back into SF using the apex data loader.

 

APEX TRIGGER FIX?:

How would I write an Apex Trigger that does this update on insert automatically whenever a record is inserted into the AccountShare object  from the external source (ie LastModifiedById in ('00590000001CEQQAA4') ) and thus allow me to avoid doing this daily manual "export>modify>import" work-around?

 

Regards,

 

Matt

  • December 11, 2013
  • Like
  • 0