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

"Too many query rows: 500001" on list?
How can I add a filter to this code to prevent this error message?
public with sharing class ApexClassHomeWork
{
public List<Account> accs {get; set;}
// retrieves the list of accounts backing the page
public ApexClassHomeWork()
{
accs=[select id, Name, BillingStreet, BillingCity, BillingPostalCode FROM Account WHERE Name LIKE 'Test%' LIMIT 10];
}
public void createContact(Id acctId)
{
list<contact>contList = newlist<contact>();
for(Integer i=0; i<500; i++)
{
Contact c = new Contact(AccountId=acctId, "last name");
contList.add(c);
}
if(contList.size()>0)
update contList;
}
}
public with sharing class ApexClassHomeWork
{
public List<Account> accs {get; set;}
// retrieves the list of accounts backing the page
public ApexClassHomeWork()
{
accs=[select id, Name, BillingStreet, BillingCity, BillingPostalCode FROM Account WHERE Name LIKE 'Test%' LIMIT 10];
}
public void createContact(Id acctId)
{
list<contact>contList = newlist<contact>();
for(Integer i=0; i<500; i++)
{
Contact c = new Contact(AccountId=acctId, "last name");
contList.add(c);
}
if(contList.size()>0)
update contList;
}
}
What you can do it show the proper error message is, create an apex exception class and though it from try and catch
Would you say the updated line should be
accs=[select id, Name, BillingStreet, BillingCity, BillingPostalCode FROM Account WHERE Name == 'Test%' LIMIT 10]
Using == instead of LIKE?