function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Luciano Castro 2018Luciano Castro 2018 

Systems Error - Please help

Hi Team, 

I have the following code which is bringing me headaches :) 

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)
    {
        for(Integer i=0; i<500; i++)
        {
            Contact c = new Contact(AccountId=acctId);
            insert c;
        }
    }
}


When calling the method "create contact", I get these errors  messages:

1. "LastName is required" - What do I need to update to resolve this issue?

2. "Too Many DML Statements 151"

3.  "Too many query rows: 500001"

Please help !!
 
Thomas MonsonThomas Monson
try this
public void createContact(Id acctId)
    {
        list<contact> Cs = new list<contact>();
        for(Integer i=0; i<500; i++)
        {
            Contact c = new Contact(firstname ='test', lastname='tst', AccountId=acctId);
            cs.add(c);
            
        }
        insert cs;
    }
Luciano Castro 2018Luciano Castro 2018
Hi Thomas, 

I am working on this and now I am having trouble only with number 3. "Too many query rows: 500001"

I understand the governance limit where you cannot query more than 50000 records in a single query. How do I add a filter to prevent this from happening?
Thomas MonsonThomas Monson
are you calling this method from another class?