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

Dealing with a SOQL Query limit
I have the next code:
---------------------------------------------------------------------
List<User> lUsers = [select federationIdentifier, email, firstName, lastName, ContactId, isActive from User where isActive=True and FederationIdentifier != ''];
List<Account> lAccounts = new List<Account>();
for (User U:lUsers)
{
Account uAccount = [select Id, PersonContactId, net_id__pc, personemail, firstName, LastName from account where PersonContactId = :U.ContactId].get(0);
uAccount.net_id__pc = U.federationIdentifier;
lAccounts.add(uAccount);
}
system.debug(lAccounts);
--------------------------------------------------------------
But I am getting a System.LimitException: Too many SOQL queries:101. Is there any other way to write this code and avoid this problem?
Thanks
---------------------------------------------------------------------
List<User> lUsers = [select federationIdentifier, email, firstName, lastName, ContactId, isActive from User where isActive=True and FederationIdentifier != ''];
List<Account> lAccounts = new List<Account>();
for (User U:lUsers)
{
Account uAccount = [select Id, PersonContactId, net_id__pc, personemail, firstName, LastName from account where PersonContactId = :U.ContactId].get(0);
uAccount.net_id__pc = U.federationIdentifier;
lAccounts.add(uAccount);
}
system.debug(lAccounts);
--------------------------------------------------------------
But I am getting a System.LimitException: Too many SOQL queries:101. Is there any other way to write this code and avoid this problem?
Thanks
try this.