You need to sign in to do that
Don't have an account?
Kristen Lund
Add profile to string query
Hello Developers - - I have a string query that I use to identify users, but am struggling adding the unique profile to the current string:
String query = 'SELECT Id, User__c FROM Contact WHERE User__c != null AND User__r.IsActive = true';I've tried to add the profile via User__r.Profile = 18digit User__r.ProfileId = 18digit, User__r.Profile.Id = 18 digit, User__r.ProfileName = Community Name, but nothing has worked. I don't feel like it should be this difficult to add in a profile to the string. Any suggestions would be greatly appreciated! Thank you!
You have to escape the simple quotes with "\" (antislash) here.
String query = 'SELECT Id, User__c FROM Contact WHERE User__c != null AND RecordTypeId =\'18Digit\'';
It is a common problem with queries in apex.
Alain
All Answers
User__r.Profile.Id or User__r.ProfileId = '18 digit' : should work for sure.
What is the error?
Strange. ( Setup > Contact : Record Types)
select id, name,sobjecttype from recordtype where sobjecttype = 'Contact'
You have to escape the simple quotes with "\" (antislash) here.
String query = 'SELECT Id, User__c FROM Contact WHERE User__c != null AND RecordTypeId =\'18Digit\'';
It is a common problem with queries in apex.
Alain
User__r.ProfileId = \' 18 digit \' inside a query delimited itself with simple quotes.