I’m lazy, especially when I’m coding, but it always hurts eventually.
I’ve a simple example requirement:
Make a Call-Out to a backend Service and save the result in a record.
What I did:
I have a nice and tidy invocable method that makes the call-out and saves the result as a record.
I added that method to a record trigger flow and everything was fine… until I needed to do a second call-out as part of that flow after the first call-out using the result.
You all know, no call-out when you have pending database changes, too bad… 🙁
Following the single responsibility concept (or microservice, or modularization…) I split up the functionality in distinct business capabilities:
1) One method to do the call-out which returns the result.
2) A second method to do the second call-out which uses the result of method one
3) A third method that saves the result in a record .
-> Using that concept I was able to add the new, second call-out before the record update.
PS: Since I started watching Matthew Gerry videos on the SOLID principles, I know at least what rules I’m breaking and how to fix them.
PPS: I know, there’s still plenty to optimize but at least I’m starting to become a better developer.