-4
Hotel__c ht=[select Guest Name__c, Room Type__c from Hotel__c where Hotel Name__c=R-0005];
System.debug('play'+ht);

here it gives error

Line: 1, Column: 10 Unexpected token 'ht'.

2
  • 3
    DML are statements like insert myList; and update aRecord;. What you have here is a SOQL query. Also, unsure if this would cause the error but you're missing the single quotes around R-0005 at the end of your query (string literals must be enclosed in single quotes).
    – Derek F
    Commented Apr 18, 2022 at 12:09
  • Is it supposed to be Guest_Name__c, Room_Type__c, Hotel_Name__c? (Note the underscores that are not in your original post.) Be sure you are using the correct API Name of the fields and not the Field Label.
    – Moonpie
    Commented Apr 19, 2022 at 16:23

1 Answer 1

6

There are a few syntax errors with the SOQL query that are causing this error to occur.

  1. It looks like you are trying to alias the field names; however, this feature is only available for aggregate queries. To resolve this issue you'll need to remove Guest, Room, and Hotel from the query.

  2. R-0005 must be wrapped in single quotes since it is not a SOQL keyword.

Hotel__c ht=[select Name__c, Type__c from Hotel__c where Name__c='R-0005'];
System.debug('play'+ht);
3
  • Line: 1, Column: 13 select Name__c, Type__c from Hotel__c where ^ ERROR at Row:1:Column:8 No such column 'Name__c' on entity 'Hotel__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
    – user113820
    Commented Apr 19, 2022 at 6:49
  • Now i am getting this error
    – user113820
    Commented Apr 19, 2022 at 6:49
  • why it shows 'ht' is invalid
    – user113820
    Commented Apr 19, 2022 at 6:50

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