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
Ricardo Aguilar 4Ricardo Aguilar 4 

Save button not working on Visualforce Page

Good morning, 
I have created two visualforce pages A and B and assign them to 2 record types, using an apex class. The only problem I have is when clicking save button on the visualforce page, both save the record in the same record type. I mean, the apex class works redirecting the user to the specific record type, but is not working when saving the information because for both visualforce pages they save the information in record type A. Do I need to create another controller for the save button? I'd appreciate any help for this.
Neha AggrawalNeha Aggrawal
Hi,

You will need to post the code for both Visualforce pages and controller. Without checking the code, it is not possible to help.
 
Ricardo Aguilar 4Ricardo Aguilar 4
VISUALFORCE PAGE A
<apex:page standardController="ADELTESurvey__c" lightningstylesheets="true">
  <h1>CUSTOMER SATISFACTION SURVEY - DELIVERY</h1>
  <apex:form >
  
  <apex:pageBlock title="Customer Information">
  <apex:pageBlockSection columns="2">
   <apex:inputField value="{! ADELTESurvey__c.Contact__c}"/>
   <apex:inputField value="{! ADELTESurvey__c.Account__c}"/>
   <apex:inputField value="{! ADELTESurvey__c.Opportunity__c}"/>
   <apex:inputField value="{! ADELTESurvey__c.Survey_date__c}"/>
  </apex:pageBlockSection>
  </apex:pageBlock>
<apex:commandButton action="{! save }" value="Save" />
  
</apex:form>
</apex:page>

VISUALFORCE PAGE B
<apex:page standardController="ADELTESurvey__c" lightningstylesheets="true">
  <h1>CUSTOMER SATISFACTION SURVEY - OPERATION</h1>
  <apex:form >
  
  <apex:pageBlock title="Customer Information">
  <apex:pageBlockSection columns="2">
   <apex:inputField value="{! ADELTESurvey__c.Contact__c}"/>
   <apex:inputField value="{! ADELTESurvey__c.Account__c}"/>
   <apex:inputField value="{! ADELTESurvey__c.Opportunity__c}"/>
   <apex:inputField value="{! ADELTESurvey__c.Survey_date__c}"/>
  </apex:pageBlockSection>
  </apex:pageBlock>
<apex:commandButton action="{! save }" value="Save" />

</apex:form>
</apex:page>

VISUALFORCE REDIRECT
<apex:page standardController="ADELTESurvey__c" extensions="NewSurveyExtension" action="{!redirectToNewVFPage}" lightningstylesheets="true">
</apex:page>

APEX CLASS
public class NewSurveyExtension {

    public String recordTypeId;

    public NewSurveyExtension(ApexPages.StandardController std) {

    }

    public Pagereference redirectToNewVFPage(){
        Pagereference pg = null;
        if(ApexPages.CurrentPage().getParameters().get('RecordType') != null){
            recordTypeId = ApexPages.CurrentPage().getParameters().get('RecordType');
            if(recordTypeId == Schema.SObjectType.ADELTESurvey__c.getRecordTypeInfosByName().get('Delivery').getRecordTypeId()){
                pg = new Pagereference('/apex/Satisfaction_Survey_Delivery'); // Add Parameters to Page if Needed

            }else if(recordTypeId == Schema.SObjectType.ADELTESurvey__c.getRecordTypeInfosByName().get('Operation').getRecordTypeId()){
                pg = new Pagereference('/apex/Satisfaction_Survey_Operation'); // Add Parameters to Page if Needed
            }
            pg.setRedirect(true);
            return pg;
        }
        return null;
    }
}
Neha AggrawalNeha Aggrawal
Hi,

Since you are using standard controller, record id of the new record will be determined by the profile of the user. Check the profile of the user who is creating the records. 

User-added image

In the above case, on creating a lead record system will ask me the record type to be assigned. If however, I remove the checkbox for Hardware from assigned record type, when I create a new lead it will be created with Consulting record type.

Does that help ?
Thanks.