function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sreekanth reddysreekanth reddy 

Record Type Query

Hi All

How to get record type in Query.
I am trying below query.
it's Not Working.


 String qry = 'select id, name, Country__c,RecordType.Name from Contact where name LIKE \'%'+searchText+'%\' and  RecordType.Name =srikanth order by name';

Thanks
Srikanth.
James LoghryJames Loghry
Srikanth,

You need to surrond the record type name with single quotes.  However, since you're using dynamic soql, you'll also need to escape the quotes.

Furthermore, I would suggest using DeveloperName instead of Name for RecordType queries, as DeveloperName will not change (unless the RecordType is deleted and recreated), but Users or Administrators can change the Name itself of a record type for label or translations.

Try the following:
 
String qry = 'select id, name, Country__c,RecordType.Name from Contact where name LIKE \'%'+searchText+'%\' and  RecordType.DeveloperName = \'srikanth\' order by name';