2

I came up with one question which asks me to select two options. Question is: When would a developer use a custom controller instead of a controller extension? Options are:

  1. When Visualforce page needs to replace the functionality of standard controller.
  2. When Visualforce page does not reference a single primary object.
  3. When Visualforce page should not enforce permissions of field-level security
  4. When Visualforce page needs to add new actions to a standard controller.

To me correct answer is: 2 and 3. But it is telling the correct answer is 1 and 3. Just wanted to check here if my understanding is wrong.

The reason why I don't want option 1 is that with controller extension we can always replace the default functionality of standard controller like custom save in controller extension.

1
  • 1
    Where did you get this question? Could be it is wrong
    – Eric
    Commented Dec 16, 2016 at 8:30

1 Answer 1

3

According to me answer will be 1 and 3.

Controller extension leverages the built-in-functionality of Standard Controller, but overrides one or more actions.

Where as, Custom Controller replaces the functionality of Standard Controller without leveraging it.

There is a significant difference in between leveraging and replacing.

Also, think about that, a class to be recognized as controller extension it must have a constructor that takes a single argument of type ApexPages.StandardController or custom controller you want to extend.

For more information, refer What are Custom Controllers and Controller Extensions?

Hope, it makes sense!

You must log in to answer this question.

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