1

I am referring to an apex class from the Process Builder. The process is executed when the owner of any record changes. Based on that, I am changing the owner of other object's records (the object is private). So can I make my apex class without using the sharing keyword? Will it be a good practice and pass the security review?

2
  • Your question is a bit unclear to me about the relationships. It sounds like you have at least two objects, one of which has private sharing. Is it a case where the owner of any record changes on any object, you are changing the owner of the private object? If so, what is the sharing on the object that triggers the process? Are the two objects related in any way? Was the owner of the initial object also the owner of the private object?
    – crmprogdev
    May 13, 2015 at 13:04
  • Actually i have 3 objects Account,Opportunity,Custom Object. Custom Object is set to private. When Account owner changes implicitly opportunity owner changes. I want the same impact to my custom object. My custom object is also related to Account. I donot want to use account trigger, so created process which executed when account owner get changed. May 14, 2015 at 7:15

1 Answer 1

1

Generally, it's always preferable to create a class using the "with sharing" keyword.

As I understand your scenario, what amounts to workflow, as created using the process builder, is using the new class to change ownership of Account related records in an object where sharing is private. The change of ownership is based on change of ownership of the Account (you've not told us what the sharing on Account is).

Since the change is done via workflow, sharing on the class isn't critical. If someone has permission to initiate the change of ownership of the Account in a Record Detail page, then it would seem obvious they'd have permission to change ownership of the related record that should transfer ownership with the Account that it's related to via the workflow you've set up using process builder.

I'd recommend adding "with sharing" to the class if your Account sharing model will support it. If it won't, then omitting it makes sense from a business standpoint and can be justified from a security standpoint since the class mirrors what's happening with the Account ownership.

You must log in to answer this question.

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