I have a LWC that essentially collects data in a table format.
I am then using an apex action (apex class) to parse the text string output of the LWC back to a record - see the code below:
public without sharing class PointofConnSingle {
//input details that comes to apex from flow
public class FlowInputs{
@InvocableVariable
public string applicationIdString;
@InvocableVariable
public string propertyChildStringArray;
}
@InvocableMethod(label='Point Of Connection Saving Single Apex')
public static List<String> saveMainsData(List<FlowInputs> request){
List<string> applicationIdList = new List <string>();
List<string> propertyChildStringArrayList = new List<string>();
List<string> resultResponse = new list<string>();
List<property__c> newPropertyToInsertList = new List<property__c>();
for(FlowInputs requestItem : request){
applicationIdList.add(requestItem.applicationIdString);
propertyChildStringArrayList.add(requestItem.propertyChildStringArray);
}
try{
Id applicationId = Id.valueOf(applicationIdList[0]);
//main property array- processing Json
List<PropertyJsonClass> mainPropList = PropertyJsonClass.parse(propertyChildStringArrayList[0]);
//inserting property frist
for(PropertyJsonClass resultPropItem: mainPropList) {
property__c newProperty = new property__c();
newProperty.Application__c = applicationId;
newProperty.Type_of_Property_POC__c = resultPropItem.propertyType;
newProperty.Name = resultPropItem.propertyType;
newProperty.Units__c = filterResponse(resultPropItem.unit);
newProperty.Imp_Areas_M__c = filterResponse(resultPropItem.impAreas);
newProperty.Name = resultPropItem.propertyType;
newPropertyToInsertList.add(newProperty);
}
if(!newPropertyToInsertList.isEmpty()){
system.debug('adding property records');
insert newPropertyToInsertList;
}
}catch(Exception e){
resultResponse.add('INSERT Failed' + e);
}
resultResponse.add('OK');
return resultResponse;
}
private static integer filterResponse(String dataToFilter){
if(dataToFilter!='' && dataToFilter!=null){
return integer.valueOf(dataToFilter);
}else{
return 0;
}
}
}
This works if the value put into the Units__c or Imp_Areas_M__c field is an integer but fails if a decimal is entered.
The data is entered via a LWC that outputs a text string that this code then parses into the fields
any ideas?
I assumed the Private static class at the bottom converts the value to a integer - but obviously not
Error Message is - The number of results does not match the number of interviews that were executed in a single bulk execution request.