3

I've got a custom object Show__c that has three different RecordTypes, including one named 'Regular Show'. Using an answer found in What would be the best approach to get the recordtype id, I'm grabbing the id of the RecordType using the following:

Id regularShowId = Schema.SObjectType.Show__c.RecordTypeInfosByName.get('Regular Show').RecordTypeId;

Using SOQL, I want to now get some records out of Show__c of that RecordType. I thought the following query would do it:

Show__c[] activeShows = [select Show_Display_Name__c, Day__c 
                                         from Show__c 
                                         where Active__c = true 
                                         AND Host__c = :h.id 
                                         AND Start_Date__c <= :date.today() 
                                         AND RecordType = :regularShowId];

The Eclipse Force.com IDE complains that this is No such column 'RecordType' on entity 'Show__c', which is not true at all. I did notice in the SFDC object definition, RecordType appears as a "Standard Field" and the column title says "Field Name" instead of "API Name", so perhaps it's not accessible via the API. Is it just not possible to filter by RecordType using SOQL?

5

The name of the field on the object is RecordTypeId

Show__c[] activeShows = [select Show_Display_Name__c, Day__c 
                                         from Show__c 
                                         where Active__c = true 
                                         AND Host__c = :h.id 
                                         AND Start_Date__c <= :date.today() 
                                         AND RecordTypeId = :regularShowId];
| improve this answer | |

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.