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

displaying error when i use the below query

 getaccount = [select id,name,Billingstate,website,phone from Account where  LEFT(name,1)=:LEFT(serval,1)];  

serval is search input text value.

if the first char is correct i should get the account .

its throwing error when i use above query .


I think there's a couple of issues here:


(1) LEFT is a formula function - I'm pretty sure you can't use it in a SOQL query

(2) You can't carry out any kind of operation on the field that you are comparing to - you have to use the field name only.  So even if LEFT was valid,  LEFT(name,1) would give an error


If you want to check the first character, I think something like the following should do it:


String servalFirst=serval.substring(0,1) + '%';
getaccount=[select id, name, Billingstate, website, phone from Account where name like :servalFirst];