function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jason FJason F 

Create a SFDX force-app that works in multiple salesforce instances with different versions of standard objects

Long story short, I'm trying to write a single app for multiple salesforce because a parent company acquired other companies that are  staying in their separate instances of salesforce. I'm trying to create a single global application, but I'm getting Apex errors with my force-app classes because some properties of some objects exist in some instances but not others. My immediate challenge is when I try to write my Apex code, on SDFX force / push (to the scratch org) the compiler checks and throws an error when it sees my Apex classes attempt to access (potentially) non-existent custom properties of the Opportunity object. 

e.g. salesforce instance 1 has custom properties on the Opportunity A, B, C and instance 2 has custom properties X, Y, Z, 
My code will detect which instance of salesforce I'm using (either with custom settings or metadata -- I haven't worked that out yet), then it would only execute settings where the properties do in fact exist. In theory, the code should work fine because it will detect the right instance of salesforce and only execute the right code (the code differences are also small -- so I only want to include that in my current project).

Anyway, my problem is I am writing one application artifact / pacakge, and I don't want to replicate thousands of lines of code just because each salesforce instance requires slightly different code -- I also can't share properties between salesforce instances because each salesforce instance has a different defition of opportunity custom properties, and each instance also typically uses 500+ properties.  

What kind of solutions are viable here?
1-many force-apps? (terrible) do i have to write a separate app (and massively duplicate my code) for each salesforce instance?
2-conditional imports? (decent if possible) could i do conditional imports in my apex classes & put the extra support code in separate artifacts?
3-object inheritance? (would be nice) can I write a core artifact and extend it with my other artifacts -- and use some object inheritance across artifacts?
4-what other options do I have -- are there other possibilites? 
Andries.NeyensAndries.Neyens
Make it dynamic:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SObjects_accessing_fields.htm