-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);
  • Ajay, did you run into any errors? – rahul gawale Oct 31 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. – Kris Goncalves Oct 31 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 . – ajay bagdad Oct 31 at 14:32
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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.