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
StaciStaci 

record type on vf page not saving, defaulting to other record type

I have the following VF Pages, depending on the subscription record type its related to.  The VF pages show the correct information.  When the record is saved and I click on it, the record type is the opposite of what it should be.  Do I need to created a separate class?
 
<apex:page standardController="Support_Subscription__c" extensions="MultiAd" id="thePage">

<script>
        sforce.connection.sessionId='{!GETSESSIONID()}';
        function init(){
           var result = sforce.connection.describeLayout('Support_Subscription__c'); //to do 
           console.log(result); //parse this object to find picklist values for each record type
        }
    </script>

    <body onload="init();">    
    </body>

<apex:form >

<apex:pageblock id="pb" >


    <apex:pageBlockButtons >

        <!--<apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>-->

        <apex:commandbutton value="Save" action="{!Save}"/>

    </apex:pageBlockButtons>
     <!--<apex:pageblock id="pb1">-->

   <apex:repeat value="{!wrappers}" var="e1" id="therepeat">
        <!--<apex:repeat value="{!lstInner}" var="e1" id="therepeat">-->
        

            <apex:panelGrid columns="10">

                <apex:panelGrid headerClass="Name">

                    <!--<apex:facet name="header">Del</apex:facet>

                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">

                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>

                    </apex:commandButton>-->

                </apex:panelGrid>
                <apex:inputField id="Record_Type" value="{!e1.asset.Support_Subscription_Record_Type__c}" onchange="setValue('Subscription Purchase Agreement Assets')" rendered="false"/>

                <apex:panelGrid >

                 <apex:facet name="header">Equipment/Registered Asset Licensed</apex:facet>

                    <apex:inputfield value="{!e1.asset.Equipment_Asset_Licensed__c}" style="width:200px" />

                </apex:panelGrid>

                <apex:panelGrid >

                    <apex:facet name="header">Serial Number</apex:facet>

                    <apex:inputfield value="{!e1.asset.Serial_Number__c}" style="width:95px"/>

                </apex:panelGrid>
         
                <apex:panelGrid >

                    <apex:facet name="header">Site Location</apex:facet>

                    <apex:inputfield value="{!e1.asset.Site_Location__c}" required="true"/>

               </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">MineStar Product</apex:facet>

                    <apex:inputfield value="{!e1.asset.MineStar_Product_Sub_Pur_Agr__c}" required="true" style="width:200px" />

                </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">Version</apex:facet>

                    <apex:inputfield value="{!e1.asset.Version__c}" style="width:95px" />  

                </apex:panelGrid>
                   <apex:panelGrid >

                    <apex:facet name="header">Machine Count</apex:facet>

                    <apex:inputfield value="{!e1.asset.Machine_Count__c}" required="true" style="width:95px" />  

                </apex:panelGrid>

            </apex:panelGrid>

        </apex:repeat>
<!--</apex:pageBlock>-->

</apex:pageblock>

</apex:form>

</apex:page>
 
<apex:page standardController="Support_Subscription__c" extensions="MultiAd" id="thePage">

<script>
        sforce.connection.sessionId='{!GETSESSIONID()}';
        function init(){
           var result = sforce.connection.describeLayout('Support_Subscription__c'); //to do 
           console.log(result); //parse this object to find picklist values for each record type
        }
    </script>

    <body onload="init();">    
    </body>

<apex:form >

<apex:pageblock id="pb" >


    <apex:pageBlockButtons >

        <!--<apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>-->

        <apex:commandbutton value="Save" action="{!Save}"/>

    </apex:pageBlockButtons>
     <!--<apex:pageblock id="pb1">-->

   <apex:repeat value="{!wrappers}" var="e1" id="therepeat">
        
            <apex:panelGrid columns="10">

                <apex:panelGrid headerClass="Name">

          </apex:panelGrid>         
<!------------------------------------------------------------------------------------------------------>

 <apex:inputField id="Record_Type" value="{!e1.asset.Support_Subscription_Record_Type__c}" onchange="setValue('Caterpillar Dealer Assets')" rendered="false"/>


     
                 <apex:panelGrid >

                     <apex:facet name="header">Equipment/Registered Asset Licensed</apex:facet>

                     <apex:inputfield value="{!e1.asset.Equipment_Asset_Licensed__c}" style="width:200px" />

                 </apex:panelGrid>

                <apex:panelGrid >

                    <apex:facet name="header">Serial Number</apex:facet>

                    <apex:inputfield value="{!e1.asset.Serial_Number__c}" style="width:95px"/>

                </apex:panelGrid>
         
                <apex:panelGrid >

                    <apex:facet name="header">Site Location</apex:facet>

                    <apex:inputfield value="{!e1.asset.Site_Location__c}" required="true"/>

               </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">MineStar Product</apex:facet>

                    <apex:inputfield value="{!e1.asset.MineStar_Product_Cat_Deal_Sub__c}" required="true" style="width:100px" />

                </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">Version</apex:facet>

                    <apex:inputfield value="{!e1.asset.Version__c}" style="width:100px"/>  

                </apex:panelGrid>
                <apex:panelGrid >

                    <apex:facet name="header">Machine Count</apex:facet>

                    <apex:inputfield value="{!e1.asset.Machine_Count__c}" required="true" style="width:100px"/>  

                </apex:panelGrid>


            </apex:panelGrid>
           

        </apex:repeat>
<!--</apex:pageBlock>-->

</apex:pageblock>

</apex:form>

</apex:page>
 
/*
Class/Method Name: MultiAd
Description: Created Subscription Assets related to Support Subscription
Author/Date: Staci Gilmore 5/27/2020
*/


public with sharing class MultiAd { 
private final Subscription_Assets__c ln; 
Public string ss;
public List<AccountWrapper> wrappers{get;set;}
private Integer nextIdent=0;

public MultiAd(ApexPages.StandardController controller) { 

ss = ApexPages.CurrentPage().getparameters().get('id');

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 




public List<Subscription_Assets__c> addlic {get; set;} 
  

public PageReference Save()
{
    List<Subscription_Assets__c> addlic=new List<Subscription_Assets__c>();
    Support_Subscription__c ssid = [select id, Name, RecordTypeId from Support_Subscription__c where id=:ss];
    for(AccountWrapper wrap:wrappers)
    {
       Subscription_Assets__c lic = wrap.asset;
       lic.Support_Subscription__c = ssid.id;
       addlic.add(lic);
    }
        
    insert addlic;
    

    PageReference pageRef = ApexPages.currentPage();
    pageRef.setRedirect(true);
    return pageRef;  
      
    
}

public class AccountWrapper
{
    public Subscription_Assets__c asset{get; private set;}
    public Integer ident{get; private set;}
    
    
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        asset=new Subscription_Assets__c();
            
    }
}         
}