You need to sign in to do that
Don't have an account?

how to fetch records from a selected record type in a custom object
Hi all,
Registration__c is my custom object with 2 recordtypes Recordtype1 or RecordType2
Now i am fetching the records from recordtype1.
List<Registration__c> reg=[Select id, name, RecordType.Name FROM Registration__c
WHERE recordtypeid in (Select Id From RecordType where sobjecttype = 'Registration__c' and DeveloperName IN ('Recordtype1'))];
for(Registration__c rg : reg)
System.debug(rg.Name);
Thanks in advance.
Monika.
Registration__c is my custom object with 2 recordtypes Recordtype1 or RecordType2
Now i am fetching the records from recordtype1.
List<Registration__c> reg=[Select id, name, RecordType.Name FROM Registration__c
WHERE recordtypeid in (Select Id From RecordType where sobjecttype = 'Registration__c' and DeveloperName IN ('Recordtype1'))];
for(Registration__c rg : reg)
System.debug(rg.Name);
Thanks in advance.
Monika.
This query is correct, are you getting any error ?
Please make sure you have records for Registration object with that record type.
All Answers
This query is correct, are you getting any error ?
Please make sure you have records for Registration object with that record type.
Seems the query you have written is correct. As Himashu said please check records.
what is the use of RecorType.Name ?and how to get recordtype name from this above query
o/p
Recordtype name: recordtype1
Thanks in advance.
I beleive RecordType.Name s same used for RecordtypeId but there is a chances that Name can be same so we use normally by recordTypeId.
For getting the Name you can use 'Select Id , Name From RecordType'
Name is a field which store the display label of your record type, if you are making your own recordtype selection vf page then you need Recordtype.name so that end user can select that but if your usecase is different from this and you are not displaying record type name in any way to your end user you can skip Recordtype.name because while saving Registation__c record SFDC is only concerned about Recordtypeid.
Makes sense ?
Thanks,
Himanshu