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
Sathish Panjala 12Sathish Panjala 12 

Argument must be an inline query

Hi ... As a part of create a Schedule Batch Apex a query will return list of deals...... But I could not able to handle the list of records in Execute method.

End up with " Argument must be an Inline query"
I have written the following code for this:

global class PaymentAmountDueUpdt implements Database.Batchable<sObject>{
    global string [] email = new string[] {'xxxxxxxx.com'};
    List<Deal__c> deals;
    
    //Start method
    global Database.QueryLocator start (Database.BatchableContext BC) {
        //List<Deal__c> deals = [select id, Payment_Amount_Due__c,(select id, Payment_Date__c, Purchase_Amount__c from cash_flows__r where Payment_Satisfied__c = false order by Payment_Date__c limit 1) from deal__c ];
        Deals = new List<Deal__c>([select id, Payment_Amount_Due__c,(select id, Payment_Date__c, Purchase_Amount__c from cash_flows__r where Payment_Satisfied__c = false order by Payment_Date__c limit 1) from deal__c]);
        return Database.getQueryLocator(Deals);
    }
    
    //Execute Method
    global void execute (Database.BatchableContext BC, List<Deal__c> deals) {
          for(Deal__c d : deals){    
            if(!d.cash_flows__r.isEmpty()){
                d.Payment_Amount_Due__c = d.cash_flows__r.get(0).Purchase_Amount__c;
            }
        }
        update deals;
    }

Please suggest me where it went wrong.

Thanks !
Best Answer chosen by Sathish Panjala 12
UC InnovationUC Innovation
Hi Sathish,

Database.getQueryLocator() takes in a string as a parameter. Deals is a list of Deal__c records. To resolve this you must replace the line 3 where you declare a list of Deal__c with the following
 
String deals;

and populate it with the actual query string in order to pass it in to the getquerylocater call. Something like the following
 
deals = 'SELECT Id,  <more fields here> FROM Deal__c'

Hope this helps!

AM

All Answers

UC InnovationUC Innovation
Hi Sathish,

Database.getQueryLocator() takes in a string as a parameter. Deals is a list of Deal__c records. To resolve this you must replace the line 3 where you declare a list of Deal__c with the following
 
String deals;

and populate it with the actual query string in order to pass it in to the getquerylocater call. Something like the following
 
deals = 'SELECT Id,  <more fields here> FROM Deal__c'

Hope this helps!

AM
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for Batch job
1) http://amitsalesforce.blogspot.com/2016/02/batch-apex-in-salesforce-test-class-for.html

NOTE:- you need to pass Query and Finish method.
 
global class PaymentAmountDueUpdt implements Database.Batchable<sObject>
{
    global string [] email = new string[] {'xxxxxxxx.com'};
    List<Deal__c> deals;
    
    //Start method
    global Database.QueryLocator start (Database.BatchableContext BC) {
		
        String strDeals = 'select id, Payment_Amount_Due__c,(select id, Payment_Date__c, Purchase_Amount__c from cash_flows__r where Payment_Satisfied__c = false order by Payment_Date__c limit 1) from deal__c ';
		
        return Database.getQueryLocator(strDeals);
    }
    
    //Execute Method
    global void execute (Database.BatchableContext BC, List<Deal__c> deals) 
	{
        for(Deal__c d : deals)
		{    
            if(!d.cash_flows__r.isEmpty())
			{
                d.Payment_Amount_Due__c = d.cash_flows__r.get(0).Purchase_Amount__c;
            }
		}
        update deals;
    }
	
	global void finish(Database.BatchableContext BC) {
    }
}

Let us know if this will help you
 
Sathish Panjala 12Sathish Panjala 12
Thanks for your quick response UC Innovation and you'r solution worked like a charm !!!

Appreciated your help on this.
Sathish Panjala 12Sathish Panjala 12
Hi Amit Chaudhary 8, 

I actually have finish method as well on that class, But I didn't placed that part here. 
Because am sure that the error is not related to that method.
Anyway thanks a lot for your quick responce and time.
Sincere appologies for the confusion caused.
Sathish