1

We have several controller classes that call out to helper classes to grab data or save data. This has resulted in a few questions...

  1. Is it sufficient to simply check all permissions in the constructor to show a permissions error before the user gets to the point of querying data or saving data. To me, this seems more user friendly than waiting for a specific button click to show a permissions error. If its advisable to check in each helper method, how would everyone recommend handling an access error? Throw an exception and catch it in the controller to display a message on screen?

    public with sharing class ExampleController
    {
        public ExampleController()
        {
            if(Schema.sObjectType.Contact.isAccessible())
            {
                ContactHelper.getContact();
            }
        }
        else
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.FATAL, 'Insufficient access.'));
        }
    }
    
    
    public with sharing class ContactHelper
    {
    
        public static Contact getContact()
        {
            return [SELECT Id, Name FROM Contact];
        } 
    }
    
  2. A similar question to the above but to do with triggers. If our trigger calls a handler which updates a related record that a user may or may not have permissions to see, how should this be handled?

  • 1
    N.B. - the Force.com Enterprise Architecture (fflib) pattern on GitHub/trailhead does this automatically for you – cropredy Jun 15 '17 at 17:12
  • @cropredy Thank you for sending that. The frustration is that our app has approximately 800 lines of code and around 3-4 DML and 3-4 queries. Adding these enterprise libraries seems overkill for such a small lightweight application. I suppose everyone would have their own angle on that... What I could do is strip out just the CRUD/FLS parts of that library to fulfil our needs. – William Smith Jun 16 '17 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.