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
Leticia Monteiro Freitas 4Leticia Monteiro Freitas 4 

Select with variables

Hi, i'm trying to do component that makes a search on Account object.
But my filters are variable.
EX:
I can make a adress search input only the street, or inpunt street and the city. 

is there anyway to my select know how filter is using?
Best Answer chosen by Leticia Monteiro Freitas 4
Khan AnasKhan Anas (Salesforce Developers) 
Hi Leticia,

Greetings to you!

There are two standard composite address fields, either of which should suit your needs.

BillingAddress
BillingCity
BillingState
BillingPostalCode

ShippingAddress
ShippingCity
ShippingState
ShippingPostalCode

Try this:
List<Account> acc = [SELECT Id, Name, BillingCity, BillingStreet FROM Account WHERE BillingCity LIKE: '%por%' OR BillingStreet LIKE: '%345%'];

Or you can try this:
String bcity = '%'+BillingCity+'%';
String bstreet = '%'+BillingStreet+'%';
List<Account> acc = [SELECT Id, Name, BillingCity, BillingStreet FROM Account WHERE BillingCity LIKE :bcity OR BillingStreet LIKE :bstreet];

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas