You need to sign in to do that
Don't have an account?
ab84
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.
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.
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?