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
Heather FlorioHeather Florio 

Selecting from order table, trying to sort results

Hello. I'm working on the API and am trying to query the table named "Order" and also sort the results. I get an error because the word order is a reserved word in SQL. How do I work around this? I've tried brackets and backticks around the table name, but neither of those worked.

SELECT OrderNumber FROM Order limit 5 order by OrderNumber

How do I use the reserved word "order" as the table name?

Thank you!
Navin Selvaraj23Navin Selvaraj23
Hi Heather,

Order is the Custom Object Right. So, You should you Order__c. We should not  use reserved key word as table name or variable name like anything.

Regards,
Navin S
Heather FlorioHeather Florio
Thank you, Navin. I realize we shouldn't use reserved words, but I didn't set it up so I'm just trying to make it work.  :) 
Navin Selvaraj23Navin Selvaraj23
Yeah Heather. You are welcome.
Kindly let me know if my helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Regards,
Navin
Heather FlorioHeather Florio
Hmm, it still doesn't work. The error I get now is "SELECT Id, OrderNumber FROM Order__c WHERE Amazon_Order_Number__c=''zzz ^\nERROR at Row:1:Column:29\nsObject type 'Order__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.".

I'm fairly certain this is the standard Order object built-in to Salesforce, so that's probably not going to work.

When I use the REST Explorer, it says the API name of the object is "Order". In other languages I use  [ ] or backticks to get around this. Is there a similar thing in SalesForce?
Navin Selvaraj23Navin Selvaraj23
Just now i noticed, Order is also a salesforce standard object.
But, in SF we can able to execute the query as below:
SELECT Id, Status, Description, Type, BillingStreet FROM Order WHERE Type='Test' ORDER BY Status

Need to check in rest explorer if we need to query from there. But i am also little new to SF, I havent used api's . Regarding from API's, I dont have any idea.  If i found anything, i will keep you posted.