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
DmonikaDmonika 

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.
Best Answer chosen by Dmonika
Himanshu ParasharHimanshu Parashar
Hi 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

Himanshu ParasharHimanshu Parashar
Hi Monika,

This query is correct, are you getting any error ?

Please make sure you have records for Registration object with that record type.
This was selected as the best answer
Sunil PalSunil Pal
Hi Monika,

Seems the query you have written is correct. As Himashu said please check records.

 
DmonikaDmonika
Thank you all it is working fine now..
DmonikaDmonika
i have one more doubt

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.
Sunil PalSunil Pal
HI Monika,

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'
Himanshu ParasharHimanshu Parashar
Hi Monika,

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
DmonikaDmonika
@Himanshu Thank you for your explaination.
 
Himanshu ParasharHimanshu Parashar
@monika Please select the best answer so that other can get help from this. :)