We have developed an app for salesforce which uses the salesforce standard product (Product2) object. Now we have got a customer who instead of using the standard product object, uses a custom object for products. My question is what would be the best way for me to implement this without polluting too much of my base code as I know this is a one off case and my other customers will use the standard product object. A couple of ways I am thinking are 1) Use the existing page and controller and do some conditional checking to check if this is my special customer or not. The downside of this is that this will pollute my base code 2) Create new page and controllers for this flow by making a copy of the existing pages. The problem with this is that it will be difficult to maintain.

I would also like to know if there is a module based approach possible in salesforce where I leave my base code as it is an apply an extra module which will override the existing code. If yes kindly provide some pointers as to how this can be done

2 Answers 2


The platform doesn't support you much on polymorphic approaches, but to a degree they are possible using Dynamic SOQL together with SObject.get() and .set(). So we have created patters which allow our Quote App to come with one Controller and one Visualforce Page supporting Standard and Custom Opportunities, OpportunityLineItems, Quote, QuoteLineItems and so on. If you go fully dynamic the downside is

  • you loose most of the type safety mechanisms
  • you get a much harder time in security reviews

On the other hand providing separate APEX and Pages for all use cases simply ruled out because we allow also to use Custom LineItems with Standard Qutes or simply Opps instead of Quotes or Custom Opps. There are too many possibilities of combinations to create typed logic.

What's best in a certain situation depends most on complexity and change frequency. So as a rule thumb if you have only one derivation and change it not so often, redundant and strict typed patterns would work best. This is also the way the the platform seems to be designed for.

But if you want to do something really complex wich lots of permutations and allowed object types, going dynamic is your only chance in APEX.

Some other thoughts about such patterns you can find in my answer here AppExchange Private Listing


I came across the following link during researching a separate issue and thought that it may be what you are looking for:


The user is showing how to make the most of custom settings to avoid hard coding values.

I hope this helps?



You must log in to answer this question.

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