Integer count = [select count() from Lead where id =:leadId.Leads__c]; if(count != 0) { Lead selectedLead = [select id,firstname,lastname,email,phone from Lead
where id =:leadId.Leads__c]; CustomUser user = new CustomUser(); user.setUserId(selectedLead.id);
Becuase you your lead query is returning more than 50 rows and you are doing TWO queries inside the loop through which you are iterating over the results of your lead query.
Aside from any code changes I have a suspicion there are better ways to attack your problem. Can you describe your use case/requirement?
Right. So why don't you create a lookup from lead to Extranet_User_Mapping__c and then use the standard controlller on Extranet_User_Mapping__c to output the collection of related leads using a binding like this:
{!Extranet_User_Mapping__c.leads__r}
If you don't need to do any filtering you could get away with no apex here.
After testing several cases, I came to the finding that if a query returns more than 10 or 15 records, I get the Visualforce error: Too many SOQL queries: 101
In this method, I have a single query (without any loop), and still I get the error.
public Lead[] getSelectedLeads() { Lead[] allSelectedUsers = [select firstname,lastname from Lead where email in :listOfSuccessfulUsers]; return allSelectedUsers; }
where is getSelectedLeads being called from, and how many times? If you lazy load it does it still happen?
Code:
Lead[] allSelectedUsers = null;
public Lead[] getSelectedLeads()
{
if (allSelectedUsers == null) {
allSelectedUsers = [select firstname,lastname from Lead where email in :listOfSuccessfulUsers];
}
return allSelectedUsers;
}
Extranet_User_Mapping__c[] existingLeads = [Select Leads__c from Extranet_User_Mapping__c where Extranet_id__c =:extranet_id];
for(Extranet_User_Mapping__c leadId: existingLeads)
{
Integer count = [select count() from Lead where id =:leadId.Leads__c];
if(count != 0)
{
Lead selectedLead = [select id,firstname,lastname,email,phone from Lead where id =:leadId.Leads__c];
CustomUser user = new CustomUser();
user.setUserId(selectedLead.id);
Aside from any code changes I have a suspicion there are better ways to attack your problem. Can you describe your use case/requirement?
My requirement is to display the details of those lead ids.
The first query retrieves the ids.
The second query checks if the id exists in the Lead table & the third query gets the particulars of that lead id.
{!Extranet_User_Mapping__c.leads__r}
If you don't need to do any filtering you could get away with no apex here.
Visualforce error: Too many SOQL queries: 101
In this method, I have a single query (without any loop), and still I get the error.
public Lead[] getSelectedLeads()
{
Lead[] allSelectedUsers = [select firstname,lastname from Lead where email in :listOfSuccessfulUsers];
return allSelectedUsers;
}
Thanks,