public without sharing class PointofConnSingle { //input details that comes to apex from flow public class FlowInputs{
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;
}
}
}
}