0

I have a dynamic SOQL query where in I am using order by clause.I want to sort it by product Style

SOQL

soql = 
'select id, name,Warehouse__c,Product_Reference__r.gii__ProductStyle__r.name, 
Product_Inventory__c , Product_Reference__c,Product_Inventory__r.gii__Product__r.name,
Product_Inventory__r.gii__Product__r.gii__ProductStyle__r.name,Product_Reference__r.gii__ProductCode__c, 
Sales_Year__c,(select id,name,Quantity__c,Month__c from Forecast_Details__R)'+
' from forecast__c where Sales_Year__c =' + '\''+selectSalesYear.id +'\''+ 'and Warehouse__c =\'' + selectedWarehouse.id + '\' ' + 
filterQueryPart  + 
                ' Order By Product_Reference__r.gii__ProductStyle__r.name NULLS Last, 
Product_Inventory__r.gii__Product__r.name NULLS Last limit ' + PageSize + ' offset ' + PageNumber*PageSize;

If i am using NULLS First, its working like a charm. But in Nulls Last, it is not working, all the Product style which are null are coming first.

Can someone help me with the error??

Thanks

Samir

0

You are missing the NULLS LAST for one of the column Product_Inventory__r.gii__Product__r.gii__ProductStyle__r.name

Try this at the end of your string:

' Order By Product_Reference__r.gii__ProductStyle__r.name NULLS Last,'+
' Product_Inventory__r.gii__Product__r.name NULLS Last limit ' +
' Product_Inventory__r.gii__Product__r.gii__ProductStyle__r.name NULLS LAST '+
 PageSize + ' offset ' + PageNumber*PageSize
  • Sorry ..that is not a problem..Query Is correct.I was storing this data in a list and was sorting it using Sort() .When i commented the sort() ..it worked. Thanks for looking into this :). – Samir Feb 23 '16 at 12:39
  • 1
    Cool. Good that you figured it out yourself :) – karthikselva Feb 23 '16 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.