I just designed a VF page to select record type..... I want help in developing a controller to display all the records of that particular Record type..... i am new to Salesforce. I dont know how to write a controller.... So please anyone help in writing the controller..
That is not going to work .Please go through below :-
RecordTypes are stored in a Salesforce object called "RecordType". You have to query this object with code that looks like:
List<RecordType> = new List<RecordType>([select id, name from recordtype where sobjecttype="MyObj__c"]);
This will give you a list of the record types you have defined for your object. If you want to present a choice of record types to the user, your best bet is to loop through the list and build SelectOption objects which you can then present to the user in an <apex:SelectList> tag. The SelectOption let's you store a name and a value for each option, use the ID as the value so you can use it directly when the user selects it.
Manju,
Try below code :-
global class My_RecordTypeOnlyController {
List<RecordType> rt;
public PageReference pageRef;
public List<RecordType> getRectypes1() {
rt=[SELECT Id,Name,SobjectType FROM RecordType where sobjecttype='Contact'];
return rt;
}
public List<SelectOption> getRectypes() {
List<SelectOption> options = new List<SelectOption>();
for(RecordType r: getRectypes1()){
options.add(new SelectOption(r.id, r.name));
}
return options;
}
public String selectedRecType;
public String getSelectrt() {
return selectedRecType;
}
Public void setSelectrt(String rt){
this.selectedRecType = rt;
}
public PageReference processContinue()
{
if(selectedRecType == '012900000006a0VAAQ')
{
pageRef = Page.VFpage1;
pageRef.getParameters().put('RecordTypeId', selectedRecType);
return pageRef;
}
else if(selectedRecType == '012900000006a0WAAQ')
{
pageRef = Page.VFPage2;
pageRef.getParameters().put('RecordTypeId', selectedRecType);
return pageRef;
}
else{
return null;
}
}
public PageReference processCancel()
{
PageReference pageRef = new PageReference('/a1O/o');
return pageRef.setRedirect(true);
}
}
All Answers
Manju,
Try below code :-
global class My_RecordTypeOnlyController {
List<RecordType> rt;
public PageReference pageRef;
public List<RecordType> getRectypes1() {
rt=[SELECT Id,Name,SobjectType FROM RecordType where sobjecttype='Contact'];
return rt;
}
public List<SelectOption> getRectypes() {
List<SelectOption> options = new List<SelectOption>();
for(RecordType r: getRectypes1()){
options.add(new SelectOption(r.id, r.name));
}
return options;
}
public String selectedRecType;
public String getSelectrt() {
return selectedRecType;
}
Public void setSelectrt(String rt){
this.selectedRecType = rt;
}
public PageReference processContinue()
{
if(selectedRecType == '012900000006a0VAAQ')
{
pageRef = Page.VFpage1;
pageRef.getParameters().put('RecordTypeId', selectedRecType);
return pageRef;
}
else if(selectedRecType == '012900000006a0WAAQ')
{
pageRef = Page.VFPage2;
pageRef.getParameters().put('RecordTypeId', selectedRecType);
return pageRef;
}
else{
return null;
}
}
public PageReference processCancel()
{
PageReference pageRef = new PageReference('/a1O/o');
return pageRef.setRedirect(true);
}
}
Hi Vinit..
It is not working............
I m adding my VF page code too. Please review it once..
<apex:page standardController="B2BCampaign__c" tabStyle="B2BCampaign__c">
<apex:form >
<apex:pageBlock >
<h1>Record Type </h1>
<apex:inputField value="{!B2BCampaign__c.RecordTypeId}">
</apex:pageBlock>
</apex:form>
</apex:page>
Manju,
That is not going to work .Please go through below :-
RecordTypes are stored in a Salesforce object called "RecordType". You have to query this object with code that looks like:
List<RecordType> = new List<RecordType>([select id, name from recordtype where sobjecttype="MyObj__c"]);
This will give you a list of the record types you have defined for your object. If you want to present a choice of record types to the user, your best bet is to loop through the list and build SelectOption objects which you can then present to the user in an <apex:SelectList> tag. The SelectOption let's you store a name and a value for each option, use the ID as the value so you can use it directly when the user selects it.