Here is the apex class I am using, I want to store list<string> data from a json file into a flow variable:
global class par{
global static List<string> l = new list<string>();
@InvocableMethod(label='Get Map' description='Returns the values of Maps')
global static List<String> CallMap(){
HttpRequest req = new HttpRequest();
req.setEndpoint('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=AIzaSyBOyIQi54LMykmzSOvCuQ2naVvVQEsEfHw');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken()!= null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME))
{
string fieldName = parser.getText();
parser.nextToken();
if(fieldName == 'place_id')
{
string place = parser.getText();
system.debug(place);
l.add(place);
parser.nextToken();
}else if(fieldName == 'status')
{
string status = parser.getText();
system.debug(status);
l.add(status);
}
}
}
return l;
}
}
List<String> listToStr = new List<String>();
String allString = "";
if (!listToStr.isEmpty()) {
allString = String.join(",", listToStr);
}
List<String> returnLst = new List<String>();
returnLst.add(allString);
return returnLst;
You are returning multiple lists, but the flow expects a single list. To resolve this, you can concatenate the multiple lists into a single string and then add it to a single list to return. Afterwards, you can extract the string back into multiple lists as needed in your flow.