0

I am trying to fetch record in my trigger using SOQL using LIKE. The value I need to compare is a combination of three fields. I am trying the below code. Not sure what I am doing wrong

string DocName = ''+q.SBQQ__Account__c+' - '+q.SBQQ__Account__c+' - '+q.Name+'%';
Document d = [Select id from Document where Name LIKE ''+DocName+'' order by CreatedDate asc LIMIT 1];
Adrian Larson
  • 149,971
  • 38
  • 239
  • 420
Afroz Kazi
  • 59
  • 3
  • 14
  • what is the error? p.s. there are a lot of questions on dynamic SOQL - this is most likely to be closed as a duplicate. – glls Sep 22 '17 at 03:26
  • @SantanuBoral Not exactly, the string I want to compare is a combination of the three fields. For example my string to compare would be Account - Account - Name – Afroz Kazi Sep 22 '17 at 04:53

2 Answers2

2

This query isn't even dynamic SOQL. You just use bind syntax:

WHERE Name LIKE :docName
Adrian Larson
  • 149,971
  • 38
  • 239
  • 420
0

Hope your looking for this

string DocName ='\'' + q.SBQQ__Account__c +' - '+ q.SBQQ__Account__c + ' - '+ q.Name+'%\'';
Document d = [Select id from Document where Name LIKE :DocName order by CreatedDate asc LIMIT 1];
NITHESH K
  • 2,525
  • 2
  • 15
  • 43