Salesforce development - why is it so developer unfriendly?
I understand the need for governor limits - it's a multi-tenent environment, I get it. I understand the attempt to make it a point-and-click solution for business users who are not developers. What I don't understand is why the development environment is so anti-development...
Examples:
I was trying to create a Drop Down List in a Flow Screen - which seems like a simple task - until you try to implement business rules:
Customer needed a list of Record Types for a specific sObjectType, but wanted to filter out some of them by excluding the ones with Name like '%Locked'. This is easy in SOQL:
WHERE sObjectType = 'type' AND (NOT Name LIKE '%Locked')
To populate a Drop Down List on a Flow Screen, you use the Dynamic Record Choice - you select the object type (RecordType in this case) and then specify your filter criteria - so sObjectType = 'type' AND Name NOT CONTAINS '%Locked'. Hmm, there's no NOT option.
Okay, lets try a different way, lets say ID = 'a collection of ids', that works in SOQL. To do this, you need to create a Flow Collection of type Text. Easy enough, create a Lookup that returns a collection of sObjects of type RecordType and then Loop through them and add them to the Collection. Oops, can't do a NOT in a Lookup either. Hmm, what else can we try?
Got it! We'll create an @InvocableMethod that returns a list of Ids - you can use that in the Dynamic Record Choice to set Id equals 'collection of ids' - that works in SOQL, after all, so why wouldn't it work for this? So, I created the method with no input parameters and a return parameter of List<string> to contain my list of Ids. I use a SOQL query to filter out the records and get my list that I want, no problem. Then, in my Flow, I see the new object/method in my pallet - I can create an instance of the object and assign the output to a Flow variable - except it should be a collection - I'm confused. I'm returning a List<string>, but my only options in Flow are variables. It will let me create the collection variable in the field, but doesn't allow me to assign it. Very strange - so I use my trusty Google search and find a forum article that says they used a List<List<string>> to get it to work. I tried that, and now I can select a collection to store the results of my Apex method. So, basically, if I want to return a single value, I use List<string> and can select a variable in the Flow. If I want to return a list of values, I use List<List<string>> and then I can assign to a collection in the Flow. That makes perfect sense!
Okay - back to my Dynamic Record Choice filter - I now set it up to use Id equals 'my collection of Ids returned by the @InvocableMethod' - seems logical, but it doesn't work. Let's try 'contains' - nope. I can see the values are being returned by displaying them in a Screen Display Type - but the filter criteria isn't looking at the collection returned by the @InvocableMethod as a list. Can I even select a collection to filter against - nope. Well, at least it's consistent.
So - I can't do a NOT in my filter. I can't filter using a Collection (ie. List), even though that is possible in SOQL (so they must not be mapping the filter criteria to SOQL, or didn't think anyone would need to do what I'm doing so didn't implement that in the Flow UI). Hmm, what else can I try?
I know - I'll create a "temp" object to store the results of my @Invocable Method and then access the values from there - that works! Yay! But, I can only return 200 values for my Drop Down List, and I need to be able to do more than that. Hmm, you can't update a Flow Screen dynamically, so I guess I could display a drop down of letters to select from that filters the results on the next screen, but what if there are more than 200 that start with the same letter? This is getting crazy...
So, it looks like I'm going to have to implement something with VF - so, what was the point of having a Flow UI and doing a 'point and click' solution when it doesn't provide you with all the functionality you need? I would have expected it would at least allow me to do a NOT, or filter using a List, or provide paging when the results have more than 200 choices... you know, the basic stuff!