You need to sign in to do that
Don't have an account?
SUMAN KUMARI 70
Why is my for loop executing only for the 1st item in the list
Hi All,
I have an apex method where I hava a for loop which is iterating over a list of items. That list has 2 items in it but the loop is returning only the 1st item.
Can you guys please help me out with it and let me know where I am going wrong.
Please do help me out, why for loop is iterating only for the 1st element of the list.
I have an apex method where I hava a for loop which is iterating over a list of items. That list has 2 items in it but the loop is returning only the 1st item.
Can you guys please help me out with it and let me know where I am going wrong.
public static String getPrecission(String imageString){ try{ String modelIdValues = System.Label.quote_Id; if(!String.isBlank(quoteIdValues)){ List<String> quoteIdLst = (quoteIdValues.contains(';')) ? quoteIdValues.split(';') : new List<String>{quoteIdValues}; if(quoteIdLst.size() > 0){ String accessToken = getAccessToken(); for(String quote: quoteIdLst){ List<Vision.Precission> lstPricission = *****************; return JSON.serialize(lstPricission); } } } return JSON.serialize(new List<Vision.Precission>()); }catch(Exception e){ System.debug(e.getMessage()); return JSON.serialize(new List<Vision.Precission>()); } }
Please do help me out, why for loop is iterating only for the 1st element of the list.
All Answers
Hi Suman,
It's because you return within the loop.
Would print only 0.
Marc
But when I am trying to return outside the loop I was getting an error sayion "Variable does not exist: lstPricission".