0

I have a test class its shown an this error

System.QueryException: unexpected token: 'BY' in this line

don't get what exactly wrong with this statement

public static List<PO_Line_Item__c> fillPOLineItem(sObject childSobject,String childNameSpace,String fieldSetName, String prefix, Set<String> setPoId){
        return database.query(getPOLineItemQuery(childSobject,childNameSpace,fieldSetName,prefix,setPoId)+'ORDER BY Name Asc');
    }

This method call in test class which shown an error like this

  • better you post your getPOLineItemQuery method code as well. You may need space character before ORDER, if you don't have already – highfive Oct 10 '16 at 6:18
  • You can just debug your query string. – Reshma Oct 10 '16 at 6:19
1

There should be a space between Object Name and Order keyword

String strQuery = 'Select Id, Name from AccountOrder BY Name DESC'; // Dynamic Query String Generated

// There should be a space between Object Name and Order keyword

String strQuery = 'Select Id, Name from Account Order BY Name DESC'; 

List<Account> accountList = Database.query(strQuery);

System.debug('Account List ###'+accountList );

Dynamic SOQL

  • hi devendra i wrote like this but it not work return database.query(getPOLineItemQuery(childSobject,childNameSpace,fieldSetName,prefix,setPoId)+ '' +'ORDER BY Name Asc'); – Bonny Oct 10 '16 at 6:31
  • Give a space before ORDER keyword and check. database.query(getPOLineItemQuery(childSobject,childNameSpac‌​e,fieldSetName,prefi‌​x,setPoId)+ '' +' ORDER BY Name Asc'); – Devendra Oct 10 '16 at 6:32
0

You must be missing space between your object name and ORDER. Add a space and you are good to go.

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.