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
Nitzan MarinovNitzan Marinov 

Adding a standard field to an apex query - error

Hi there,

I'm trying to make a simple change to this Apex code, trying to add RecordType to the list of fields displayed (see in bold):

public class AttendeeController{
   // global List<SelectableAccount> accounts {get;private set;}
    public List<ClientWrapper> clientList {get;set;}
    public Set<Id> selClientIds {get;set;}
    public Boolean hasSelClient {get;set;}
    public String datename {get; set;}
   
    public AttendeeController()
    {
        
        clientList = new List<ClientWrapper>();
        selClientIds = new Set<Id>();
        
        for(Clients__c c : [Select Id, Name, RecordType from Clients__c where Name != null and active__c = true order by Name limit 999])
        {
            clientList.add(new ClientWrapper(c));
        }
        integer i = 0;

I then get this error message:
No such column 'RecordType' on entity 'Clients__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

I have confirmed that RecordType is the correct field name. It is a standard field. I have also tried selecting another standard field and I get the same mesage. When I try selecting a custome field I have no problem at all.

Can someone help pleae?
Thanks
Best Answer chosen by Nitzan Marinov
Abhishek BansalAbhishek Bansal
Hi Nitzan,

RecordType itself is not a field.
You have to use the fields of RecordType in your query.
For Eg : If you want Id of RecordType than use RecordTypeId and if you want name of RecordType than use RecordType.Name.

Please let me know if you need more clarification or any help on this.

Thanks,
Abhishek

All Answers

AvinashBAvinashB
You need to use RecordTypeId or RecordType.Name fields.
Abhishek BansalAbhishek Bansal
Hi Nitzan,

RecordType itself is not a field.
You have to use the fields of RecordType in your query.
For Eg : If you want Id of RecordType than use RecordTypeId and if you want name of RecordType than use RecordType.Name.

Please let me know if you need more clarification or any help on this.

Thanks,
Abhishek
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Nitzan,

Refer this link .It has the best answer for same type of question
http://salesforce.stackexchange.com/questions/33805/soql-obtaining-record-type-name

Thanks 
Nitzan MarinovNitzan Marinov
Thanks, all, that was very useful :-)
Ajay K DubediAjay K Dubedi
Hi Nitzan,

If  this solution is really helpful for you then please mark it best or solve  that should be useful for outher.

Thanks