-3

for below query like is not working

static final String OrgUrl=system.URL.getSalesforceBaseUrl().toExternalForm();

string sl=[select Identity_Provider__c from Org_Url__mdt where label 
like:'%'+OrgUrl+'%'].Identity_Provider__c;
System.debug('sl>>>>'+sl);
3
  • Ajay, did you run into any errors? Commented Oct 31, 2019 at 12:07
  • We need more info. Is there only one Org_url__mdt record in your system? If so, you could add LIMIT 1. Otherwise, you'll need to handle the return which would be a list, not a single result. Commented Oct 31, 2019 at 13:15
  • you can consider Only one record,the thing is the query will work for the simple string ,but if any special character in it then it not . Commented Oct 31, 2019 at 14:32

1 Answer 1

0

You have used the like operator correctly.

I think the problem is in query result assignment. You should use List<String> instead of single String in the left side of SOQL query result assignment because SOQL query can return multiple result.

use List<String>

List<String> sl = [select Identity_Provider__c from Org_Url__mdt where label 
like:'%'+OrgUrl+'%'].Identity_Provider__c;

instead of using single String sl

Or you can use single String but then you should use Limit 1 in the last of our SOQL query, so that the query return only 1 result. like

String sl = [select Identity_Provider__c from Org_Url__mdt where label 
like:'%'+OrgUrl+'%' limit 1].Identity_Provider__c;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .