+ Start a Discussion
javierjiesjavierjies 

select with %field%

Hello everyone!!

 

I'm trying to do a select. I have the object person, where I have two text fields; howAmI__c and SuperWord__c

 

 by default: SuperWord__c='pro-active'

 

 

 I want to select people with the SuperWord inside of the field  howAmI__c

 

for instead, a person with howAmI__c='I am a really pro-active person'

 

I think It's something like:

 

select  howAmI__c, SuperWord__c from Person__c where howAmI__c=%SuperWord__c%

 

but it doesn't work!!

 

Any Idea?!?!?

 

 

Thanks in advance!!!

wesnoltewesnolte

Hey

 

I don't think there's a simple way to do that :( You'd have to fetch all the records out of the database,

 

 select  howAmI__c, SuperWord__c from Person__c

 

And make a list to hold the filtered values. Loop throught the first list,

 

List<Person__c> filteredPeople = new List<Person__c>();

 

for(People__c person: [select  howAmI__c, SuperWord__c from Person__c]){

 if(person.howAmI__c.contains(person.SuperWord__c))

   filteredPeople.add(person); 

 

Be careful though because contains does a case-sensitive search.

 

Cheers,

Wes