2

I am building a performance management tool for my organization, where the top Performance__c table needs to be private, so as to obscure the quota and commission data per employee.

Challenge: Allow the records to be visible for all users, but only Id and OwnerId...

... when they create an opportunity, I have a trigger that adds them as a default "revenue split" and their partner as an "overlay split" to a new OpportunitySplit__c table which is a master-detail of the Performance__c table. They are obviously not able to add the overlay split, since they cannot see their partner's Performance__c record to insert it as the master lookup Id...

Do I need to use an @future call to accomplish this without opening up all visibility to everyone?

1 Answer 1

5

You just need an apex class that handles the logic from your trigger that is WITHOUT SHARING, which will allow you to update any fields on any Performance__c record, regardless of ownership or sharing rules.

One word of warning about classes WITHOUT SHARING... you are giving up the built in permission restrictions and basically managing them yourself within your apex logic at that point. This is powerful and introduces risk into your custom automation. You'll want to make sure to unit test not only the scenarios that you want but also the scenarios that you don't want, and confirm that they're not possible.

2
  • Interesting. The only thing I'm really worried about is viewership, so this might work. I'll give it a shot and report back shortly! Commented May 6, 2014 at 23:24
  • Ok found it. I am utilizing Hari Krishnan's trigger framework and found that I wasn't going high enough up in the chain to affect the "without sharing" fact. Once I modified the TriggerFactory class, everything worked fine. I'll have to keep this in mind as I build future triggers, but more often than not, I'd like to keep data visibility limited while data is often cross-pollinating, so I think it's going to work for me. Thanks for the bread crumb, led me down the right path! Commented May 7, 2014 at 2:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .