I came to Salesforce from the world of Java and have been working with Apex and Salesforce for a year now. I am constantly trying to implement Java (and OOP in general) programming practices in my daily development, but I cannot wrap my head around concept of declarative development. My latest opinion is that it is evil and no company that want stable working code should use it.
Consider such a problem:
- I have some Custom Objects
B. I was asked to write an
after inserttrigger for
Aobject that will create new
Brecord with lookup on inserted
- I implement such an behaviour but in few month some administrator add to the
Bnew validation rule. He receive no warnings or notifications but as soon as someone insert new
Arecord everything is crashing with hard error and they are calling me to fix the problem.
You can see few issues with this situation:
- If admin need to click "Run all tests" every time he/she add new required fieldalidation ruleuilder flow what is the point for him/her adding this thing. He/She needs to call me for such tasks.
- If he/she already called me for this task why would I make validation rule, if I would rather do it with code and cover it with tests properly.
- If I do it with code, why would I do it in trigger - same error can appear for other developers. I would rather do it in Service Layer aka "before context hit the Database Layer".
So, in general I have such questions:
Is declarative programming creates more problems then solves?
If no, how should I write my code so I will not be distracted every time Admins in the PreProd org decide to change database model and\or validations?
Honestly, I am feeling like I am missing some obvious best practice that was taught to everyone else. I do not really know how enterprise orgs from big companies like CocaCola, or MasterCard are developed. They cannot have this problem and I am curious how they overcome this.