You need to sign in to do that
Don't have an account?

Regarding Iteration of for loop of an list
for(Integer i=1;i<leadrecords.size();i++)
{
lat= leadrecords[i].Latitude__c;
longt=leadrecords[i].Longitude__c;
if (i<leadrecords.size())
{
Integer j=i++;
lat1=leadrecords[j].Latitude__c;
}
}
where leadrecords is the list and it is as follows...
private List<Lead> leadrecords;
public List<Lead> getLeadrecords()
{
return leadrecords;
}
String query = 'SELECT City,Latitude__c,Longitude__c FROM Lead WHERE City LIKE \''+city+'%\'';
leadrecords = Database.query(query);
for(Integer i=1;i<leadrecords.size();i++)
{
lat= leadrecords[i].Latitude__c;
longt=leadrecords[i].Longitude__c;
if (i<leadrecords.size())
{
Integer j=i++;
lat1=leadrecords[j].Latitude__c;
}
}
Now iam having two records in salesforce dbase whose city=bangalore..So i want to fetch each of these places corresponding latitude value which is in my LIST LEADRECORDS BUT WHEN IAM DOING AS ABOVE iam always getting the latitude value of the ist records but not the 2nd record of the loop please some one tell me how to iterate and pass the values to different strings so that i can catch those values in my javascript variables of my visualforce page..
Help me with an example so that i can clearly work out it..
Thanking You,
{
lat= leadrecords[i].Latitude__c;
longt=leadrecords[i].Longitude__c;
if (i<leadrecords.size())
{
Integer j=i++;
lat1=leadrecords[j].Latitude__c;
}
}
where leadrecords is the list and it is as follows...
private List<Lead> leadrecords;
public List<Lead> getLeadrecords()
{
return leadrecords;
}
String query = 'SELECT City,Latitude__c,Longitude__c FROM Lead WHERE City LIKE \''+city+'%\'';
leadrecords = Database.query(query);
for(Integer i=1;i<leadrecords.size();i++)
{
lat= leadrecords[i].Latitude__c;
longt=leadrecords[i].Longitude__c;
if (i<leadrecords.size())
{
Integer j=i++;
lat1=leadrecords[j].Latitude__c;
}
}
Now iam having two records in salesforce dbase whose city=bangalore..So i want to fetch each of these places corresponding latitude value which is in my LIST LEADRECORDS BUT WHEN IAM DOING AS ABOVE iam always getting the latitude value of the ist records but not the 2nd record of the loop please some one tell me how to iterate and pass the values to different strings so that i can catch those values in my javascript variables of my visualforce page..
Help me with an example so that i can clearly work out it..
Thanking You,
In this code you are initializing i=1, and then in j=i++; your if condition :- if (i<leadrecords.size()) so it will j starts from 1 and due to i++, the condition fails during second interation. Try it with i=0, i think it should solve your problem.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi thanks for your reply but iam trying to define a javascript function in visualforce page which displays array values(i pass my list of leadtype leadrecords to array variable array1 )
where leadrecords is a list of lead datatype which contains query output....
private List<Lead> leadrecords;
and i pass the query output to lead records is returned in this method...
public PageReference view()
{
String query = 'SELECT City,Latitude__c,Longitude__c FROM Lead WHERE City LIKE \''+city+'%\'';
/* In this query city is a picklist field so if i select bangalore all the records having latitude value of different places in bangalore city has tobe fetched..*/
leadrecords = Database.query(query);
for(Integer i=1;i<leadrecords.size();i++)
{
+= leadrecords[i].Latitude__c;
longt=leadrecords[i].Longitude__c;
if (i<leadrecords.size())
{
Integer j=i++;
lat1=leadrecords[j].Latitude__c;
}
}
return null;
}
Now i want to catch the leadrecords records ie Latitude__c value (record values) and store it in a variable but not to display if i want to display i might have used pageblock table So the following function trying to catch the values of leads by passing list to array and tring to catch values in for loop of array in javascript function in vpage....
function arraycheck()
{
var array1=new Array();
array1='{!leadrecords}'.replace('[','').replace(']','').split(',');
for(j=0;j<array1.length;j++)
{
document.write(array1[j] + "<br >");
var x=array1[j];//giving id of the 1st record 00Q90000001Oj4KEAS//
var y=array1[j++];//giving id of the 2nd record 00Q90000001Oj6kEAC//
alert(x);
alert(y);
}
But i want to catch the field value called Latitude__c from all the records of the list so how to loop the list and catch those values in the variable.....
Please correct me if iam wrong in my code and help me with an example code of doing what iam expecting