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
shephalishephali 

how to use string variable in where clause.

hello friends,
    here is my code.this query is not working as variable 's' contains a value say s='31'. when i write 31 in place of 's' in where clause it works.
     how to solve it as 's' is a variable not constant.please reply
  String s = String.valueof(Code);
  TableData=[select Name,Last_Name__c from lead__c where Agent_ID__c='s' ];
Best Answer chosen by shephali
Vishal_GuptaVishal_Gupta
Hi Shephali,

Please use below code :

 String s = String.valueof(Code);
 TableData=[select Name,Last_Name__c from lead__c where Agent_ID__c = :s ];

Please let me know if I can help you more.

Thanks,
Vishal

All Answers

Vishal_GuptaVishal_Gupta
Hi Shephali,

Please use below code :

 String s = String.valueof(Code);
 TableData=[select Name,Last_Name__c from lead__c where Agent_ID__c = :s ];

Please let me know if I can help you more.

Thanks,
Vishal
This was selected as the best answer
shephalishephali
Thanks Vishal for your quick response it worked!!