You need to sign in to do that
Don't have an account?

SOQL query for matching a column with a string
I am writing a trigger for updating the product according to the product name that matchs the name in a custom setting
Below is the query which I wrote, But do not understand why it is not retriving any data.
[select Trademark__c,Trademark_Word__c FROM Trademark2__c WHERE Name LIKE %p.Name%]
Here my Name = 3010 and p.Name= I3010 18X12 5E/5E 0500+-002/DI
But this is not working as 3010 is not matching the p.Name.
I know this is something simple , But I am not able to figure this out.
Any help is highly appreciated
Below is the query which I wrote, But do not understand why it is not retriving any data.
[select Trademark__c,Trademark_Word__c FROM Trademark2__c WHERE Name LIKE %p.Name%]
Here my Name = 3010 and p.Name= I3010 18X12 5E/5E 0500+-002/DI
But this is not working as 3010 is not matching the p.Name.
I know this is something simple , But I am not able to figure this out.
Any help is highly appreciated
Thank you all. It was such a simple solution , wasted like 4 hours on this!
String temp= p.Name;
List <Trademark__c> trademarkList = new List<Trademark__c>();
String myTradeMark = 'NotFound';
String myTradeMarkWord = 'NotFound';
trademarkList = [select Name, Trademark__c,Trademark_Word__c FROM Trademark__c];
System.debug('is empty '+trademarkList.isEmpty());
if(!trademarkList.isEmpty())
{
for(Trademark__c t:trademarkList)
{
if(temp.contains(t.name))
{
System.debug('Name'+t.Name);
System.debug('Trademark'+t.Trademark__c );
System.debug('Trademark word'+t.Trademark_Word__c);
myTradeMark= t.Trademark__c;
myTradeMarkWord = t.Trademark_Word__c;
break;
}
}
}
All Answers
Try this:
[select Trademark__c,Trademark_Word__c FROM Trademark2__c WHERE Name LIKE: '%'+p.Name+'%']
Happy Coding
Like is not able to match this as p.Name is not a substring of Name.
I want to match a smaller length string to a longer string as in Name is a substring of p.Name
Thank you all. It was such a simple solution , wasted like 4 hours on this!
String temp= p.Name;
List <Trademark__c> trademarkList = new List<Trademark__c>();
String myTradeMark = 'NotFound';
String myTradeMarkWord = 'NotFound';
trademarkList = [select Name, Trademark__c,Trademark_Word__c FROM Trademark__c];
System.debug('is empty '+trademarkList.isEmpty());
if(!trademarkList.isEmpty())
{
for(Trademark__c t:trademarkList)
{
if(temp.contains(t.name))
{
System.debug('Name'+t.Name);
System.debug('Trademark'+t.Trademark__c );
System.debug('Trademark word'+t.Trademark_Word__c);
myTradeMark= t.Trademark__c;
myTradeMarkWord = t.Trademark_Word__c;
break;
}
}
}