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
ab84ab84 

Basic SOQL Query for RecordType of Custom Object

Hi,

I've created a custom object and a page to display the data.

I have now updated the object by adding record types.  What I want to do is update either the class or the page so that the page only displays the data for one particular record type.

My SOQL query is currently:

String strSql = 'SELECT Id, Name, Preview_Text__c, NewsBody__c, CreatedDate, Sort_Date__c, Published__c, RecordType.ID FROM News__c WHERE Published__c = TRUE ORDER BY Sort_Date__c DESC';
return database.query(StrSql);


I have tried changing this to;

String strSql = 'SELECT Id, Name, Preview_Text__c, NewsBody__c, CreatedDate, Sort_Date__c, Published__c, RecordType.ID FROM News__c WHERE Published__c = TRUE AND RecordType.ID="WHATEVER THE ID IS" ORDER BY Sort_Date__c DESC';
return database.query(StrSql);

This displays an error.  Can anyone advise on the correct way to handle this requirement?  I will want to do another page later that includes the data for the other type.
kevin lamkevin lam
Just change the two occurrences of "RecordType.ID" to "RecordTypeId".
Ramu_SFDCRamu_SFDC
Please change the RecordType.Id to RecordTypeId .
ab84ab84
I tried that already, I changed my code to:

String strSql = 'SELECT Id, Name, Preview_Text__c, NewsBody__c, CreatedDate, Sort_Date__c, Published__c, RecordTypeId FROM News__c WHERE Published__c = TRUE AND RecordTypeId=012c00000004Sds ORDER BY Sort_Date__c DESC';
return database.query(StrSql);

But this displays the error:

line 1:157 no viable alternative at character '"'
An unexpected error has occurred. Your development organization has been notified.

So I removed the double quotes from within the SOQL string and this offers the error:

unexpected token: c00000004Sds

Any suggestions on the correct way to do this in the SOQL query?