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
davidjbbdavidjbb 

SQL Syntax

Hello,

 

I'm having trouble with the following code. I'm fairly new to development so please bare with me.

 

private String abcd; 

private List <WorkReason__c> wrReason;

 

abcd = "Example"

 

wrReason = [Select Name from WorkReason__c where Name = abcd];

 

i''m getting an error where Name = abcd. Are we not allowed to use a varaible in place of      'string value' ?



 

Best Answer chosen by Admin (Salesforce Developers) 
birdofpreybirdofprey

You are using databinding of a variable so you will need to add in this ":", so try this.

 

wrReason = [Select Name from WorkReason__c where Name =: abcd];

All Answers

birdofpreybirdofprey

You are using databinding of a variable so you will need to add in this ":", so try this.

 

wrReason = [Select Name from WorkReason__c where Name =: abcd];

This was selected as the best answer
davidjbbdavidjbb

Thank you birdofprey.

 

 

craigmhcraigmh

This syntax also works:

 

wrReason = [Select Name from WorkReason__c where Name = :abcd Limit 10000];