I am trying to insert a case using anonymous apex but I keep getting an error unexpected token 'test1'. Could somebody help to understand what's wrong with this code? In other threads, people pointed out that brackets are missing but I have all the needed characters.

Case test1 = new Case(BusinessHoursId=01m7000000007vPAAQ,
                      Subject='INCOMING CALL ');
insert test1;


Line: 1, Column: 6
Unexpected token 'test1'.
  • Do you have a class in your org called "Case" or "Test"? If so, you need to rename that class.
    – Derek F
    Commented Jun 17, 2021 at 11:49
  • No, but in this trailhead you can see it's possible to create contact in this why, so why not a case? trailhead.salesforce.com/content/learn/modules/apex_database/…
    – P1otr
    Commented Jun 17, 2021 at 11:52
  • You can create a Case like this (as you can for any other SObject). The issue has something to do with the Case test1 part rather than the = new Case(...) part. Accidentally shadowing the Test type (by having an Apex class saved in your org like public class Test{ ...} is just the most common reason why you'd get an error like that. Please double check the classes in your org. If you still don't find any class named "Test", then try changing your variable name to not include the word "test".
    – Derek F
    Commented Jun 17, 2021 at 11:57
  • I changed "test1" to "blabla" and it's the same :/
    – P1otr
    Commented Jun 17, 2021 at 12:00
  • BTW, welcome to Salesforce Stack Exchange.
    – Moonpie
    Commented Jun 17, 2021 at 12:06

1 Answer 1


Put your id values in single quotes.

E.g., BusinessHoursId='01m7000000007vPAAQ',

For learning purposes, hard coding id values if fine. As you expand your knowledge and understanding, and get into "real world" scenarios, be sure to get any id values dynamically - via a SOQL query or other dynamic means.

  • Yes, I just discovered that, thanks, it worked!
    – P1otr
    Commented Jun 17, 2021 at 12:02
  • Moved entire contents of this comment as an addendum to the original answer.
    – Moonpie
    Commented Jun 17, 2021 at 12:04

You must log in to answer this question.

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