0

I am trying to read the values from an existing lead that was initially created, however, the snippet I am using is giving me this error:

Compile Error: unexpected token: 'Lead' at line 1 column 7

Here's a snippet of the code I am using:

public Lead l { get; set; } 
l = [SELECT Id, FirstName, LastName, Company, Email FROM Lead WHERE Id = :leadid];
  • 2
    Do you have class named Lead in your org ? – Mohith Shrivastava Aug 19 '16 at 15:08
1

Your code should look something like this:

public Lead l { get; set; } // The semi-colon separator is important.

Your query should also be modified:

[SELECT Id, FirstName, LastName, Company, Email FROM Lead WHERE Id = :leadid];

You were missing the :, which creates a bind expression, allowing you to use an apex variable inside of your soql query.

Try updating the code you have now to have the correct syntax and hopefully that makes some of your issues go away. If you are still having trouble with issues like this, I'd recommend running through the Developer Trailhead. Its a great introduction to development on the force.com platform.

  • Good day @battery.cord thank you for your response, my apologies I had made some typos the code is as specified below: public Lead l { get; set; } l = [SELECT Id, FirstName, LastName, Company, Email FROM Lead WHERE Id = :leadid]; I am still getting the error though. – user23 Aug 19 '16 at 15:02
  • 1
    The snippets as you have posted them will run perfectly fine. As @Mohith suggested, try checking for apex classes named Lead. If there are none, I'd recommend editing your post to provide the class which contains these snippets, otherwise, I don't think anyone will be able to help further. – battery.cord Aug 19 '16 at 15:10
  • thank you very much will definitely go through the Developer Trailhead. No there was no lead class @Mohith, I had definitely left out the bind expression. Thank you for the assistance – user23 Aug 20 '16 at 14:10
1

The error says it is at line 1. The declaration of a class variable should not be at line 1.

public class User23sStuff {
  public Lead l { get; set; } 
  public void aMethod {
     l = [SELECT Id, FirstName, LastName, Company, Email FROM Lead WHERE Id = :leadid];
  } 
 ....
}

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.