1

I have a query in my apex code:

oldcrashes=[SELECT Id,OCTO_End_User_Service_Contract__c,OCTO_Closure_Reason_Text__c,OCTO_Validated_By_OTP__c,ClosedDate,Status 
                    FROM Case WHERE RecordType.Name='CRASH DOSSIER – PRO ACTIVE NOTIFICATION'
                    AND Status='Closed' 
                    AND OCTO_End_User_Service_Contract__c=:currentCase.OCTO_End_User_Service_Contract__c
                    ORDER BY ClosedDate desc 
                    LIMIT 3];

The system when i try to save throws the error:

expecting right square bracket, found 'ORDER BY ClosedDate desc '

I don't understand why. Someone can help me please?

1
  • 3
    Nothing stands out for me. Suggest you try removing terms one by one from the where clause to isolate the problem.
    – Keith C
    Jan 9, 2017 at 17:58

1 Answer 1

0

Try to put currentCase.OCTO_End_User_Service_Contract__c into a variable. And run the query changing

OCTO_End_User_Service_Contract__c=:currentCase.OCTO_End_User_Service_Contract__c

into

AND OCTO_End_User_Service_Contract__c=: myVar
6
  • Done.Same error Jan 9, 2017 at 17:48
  • What type of field is OCTO_End_User_Service_Contract__c ? If you delete this condition, it works ?
    – ransommule
    Jan 9, 2017 at 17:58
  • is a custom field. Jan 9, 2017 at 18:01
  • yes, i know, but it a formula field ?
    – ransommule
    Jan 9, 2017 at 18:03
  • 1
    no it's a lookup field. I figured out what was the problem. I copied the query from previous apex code, but somehow the copy/paste failed. I tried again with copy/paste and now the query works properly. Jan 9, 2017 at 18:18

You must log in to answer this question.

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