I am building a Flow that takes a user through a wizard to create a custom contract object with detail objects that represent the products on that contract (stored as a junction object). An issue I ran into is that Flow has a known limitation where if you use a Dynamic Choice (i.e. creating a dynamic set of checkboxes to choose Products from based on records from the Product object) it can only store the choices as a long semicolon delimited string in a variable; it cannot create detail objects based on your dynamic selection (even using a loop).
To get around this, I want the flow to just create the parent Contract, then I want an after insert Apex trigger to parse the field where the long string of semicolon separated Product Ids are stored. The trigger would need to take the string and find each Id to store in a List. Once I had the List made from the text field I could insert the Product detail records to the parent Contract.
I am very new to Apex, mostly just a point and click admin here. I am struggling with how to use RIGHT and LEFT to loop through the string field.
trigger AddProductstoSOW on PS_Contract__c (after insert) {
for(PS_Contract__c c:Trigger.new){
List<Id> ProductsToInsert = new List<Id>;
integer n = LEN(c.Initial_Services_Products__c);
for(p=15,p<n,p+17){
//How to iterate through Initial_Products_Selected__c?
thisId = LEFT(p);
Id product = Id.valueOf(thisId);
ProductsToInsert.add(product);
}
}
insert ProductsToInsert;
}
Any help is very appreciated.