0

How do I get resolved in this?

Here's what's been tried so far.

global class Batchupdate implements Database.Batchable<sObject> {
    global Integer recordsProcessed = 0;  
    global List<Sales_Order_Line__c> start(Database.BatchableContext BC){
       list<Sales_Order__c> sales=database.query(getso());
        List<Sales_Order_Line__c> sol = new List<Sales_Order_Line__c>();
          sol= [select id,Description__c,Extended_Price__c,Fulfillment_Source__c,Item__c,Line__c,Need_Date__c,Ordered_Date_Time__c,Quantity_Ordered__c,Quantity_Available__c,Status__c,Unit_Price__c,Sales_Order__c  from Sales_Order_Line__c where Sales_Order__c=:sales and (Quantity_Ordered__c >= Quantity_Available__c)];  
            System.debug('sol' + sol);
        return sol;
        }
    global void execute(Database.BatchableContext bc, List<Sales_Order_Line__c> sol){
        List<Sales_Order__c> so=[Select id, Date_Time_Ordered__c,Need_Date__c,Type__c ,Order_Status__c from Sales_Order__c];
        list <Sales_Order_Line__c> updatedso = new list<Sales_Order_Line__c>();
        for(Sales_Order_Line__c soline: sol){
            soline.Sales_Order__r.Order_Status__c = 'closed';
                updatedso.add(soline);
         }

        update updatedso;
        }
    global void finish(Database.BatchableContext bc){

    }

public String getso()
{
   String query= 'Select id, Date_Time_Ordered__c,Need_Date__c,Type__c, Order_Status__c from Sales_Order__c';
    return query;
}
}

2 Answers 2

2

You cannot compare two different field values in your SOQL 'where' clause. E.g. the below is not allowed.

'Quantity_Ordered__c >= Quantity_Available__c'

What you can do to achieve your need is create a formula field to compare this two custom field, and use the custom field in your SOQL where clause.

3
  • can you tell me what is the exact formula syntax to be applied for the field?
    – Aishwarya
    Apr 30, 2020 at 5:36
  • when i tried this IF(Quantity_Ordered__c <= Quantity_Available__c) Iam facing the error as Error: Incorrect number of parameters for function 'IF()'.
    – Aishwarya
    Apr 30, 2020 at 5:38
  • @Aishwarya In your formula field, it will be something like: IF(Quantity_Ordered__c >= Quantity_Available__c, TRUE, FALSE). More info on syntax: help.salesforce.com/…
    – EugeneO
    Apr 30, 2020 at 8:25
0

You can create a formula field or perform check in the loop itself as below

For(Sales_Order__c s: sol) {
if(s.Quantity_Ordered__c > s.Quantity_Available__c){
    solList.add(s);
}}

Then you can use solList

2
  • Should I need to execute the FOR loop in the start method?
    – Aishwarya
    Apr 29, 2020 at 6:41
  • Yes, and you can return solList after the loop. Apr 29, 2020 at 6:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .