Skip to main content

Hello, Dear Fellow Colleagues,

I hope everyone is doing great and coding Apex! :)

I have a question and I really would like to understand to solution. Can you please help me with what line 7 gives an error? I made a SOQL, collected my list of opportunities, and passed them in the getQueryLocator. But I got this error. I really would like to understand how to fix this and what the actual argument must be in line query mean. Thank you very much for your time and help in advance.

 

I have copy the entire SOQL from closed parenthesis to close parenthesis and paste it as an argument in getQueryLocator directly and delete the "List<Opporunity> opps = " part. When I do this the error goes away. But I like to know why I cannot pass "opps" as argument?

5 risposte
  1. 16 feb 2023, 14:55

    Hi @Isaac Yalcin,

     

    As we are writing a batch class in which we use the Database method, we should use Dynamic SOQL rather than Standard SOQL for this.

     

    Just replace your lines 6 and 7 with these, Also please go through the link:

     

    String oppQuery = 'SELECT Id,Name,LeadSource FROM Opportunity';

    return Database.getQueryLocator(oppQuery);

0/9000