I have a flow and due to the complexity of the logic, I moved some of the logic into apex (However I need to use minimum apex).
I'm looping through some records and finding related records (I need only one to be added to the list). And if there are no records found, I'm adding the Id to a list of Strings (Later I need it to send an email from the flow).
But how can I pass the list of Strings back to the flow in addition to the list of records I'm returning? Is there a way to set flow variables from apex instead of returning?
@InvocableMethod
public static List<List<Maintenance__c>> getMaintenanceRecordsToBeCloned(List<List<Maintenance__c>> mains){
List<Maintenance__c> maintenances = mains.get(0);
List<Maintenance__c> listTobeCloned = new List<Maintenance__c>();
List<String> missingRecords = new List<String>();
Property_Agreement__c[] props = [SELECT Name, Id FROM Property_Agreement__c WHERE Active_c=True];
//doing the following to get only one Maintenance record per Agreement
for(Property_Agreement__c prop : props){
Boolean isRecordFound = false;
for(Maintenance__c main: maintenances){
if(main.Property_Agreement__c == prop.Id){
listTobeCloned.add(main);
isRecordFound = true;
break;
}
}
if(!isRecordFound){
missingRecords.add(prop.Id);
}
}
List<List<Maintenance__c>> result = new List<List<Maintenance__c>>();
result.add(listTobeCloned);
//is there a way to return missingRecords too?
return result;
}