0

When i change the record type value(technical or no technical) , i need to hide/show email__c, isClassTeacher__c and i need to show filtered picklist values based on record type selection for the filed designation__c. In one word, I am trying to replicate the standard pagelayout behavious(after selecting the record type, some filds will be hidded(paglayout selection) and some picklist vlaues will change. the same behaviour i am trying to make it...i used extension...to add extra functionality only. can anyone please help me.

  <apex:page showheader="true" sidebar="false" id="page" standardController="Managment__c" extensions="Management_Ext1">
    <apex:form>
        <apex:outputpanel id="one">
            Selected RecordTypeValue---> {!Managment__c.RecordtypeID}
        </apex:outputpanel>

        <apex:pageBlock id="Details">

            <b><apex:outputLabel value="RecordType " for="recType"></apex:outputLabel></b>

            <apex:selectList size="1" value="{!Managment__c.RecordtypeID}" id="recType">
                <apex:selectOptions value="{!RecordTypeValues}" />
                <apex:actionSupport event="onchange" reRender="one" />
            </apex:selectList>
            <br/>

            <apex:pageBlockSection columns="1" collapsible="false">
                {!Managment__c.RecordtypeID}
                <apex:inputfield value="{!Managment__c.Name}" required="true" />
                <apex:inputfield value="{!Managment__c.email__c}" />
                <apex:inputfield value="{!Managment__c.isClassTeacher__c}" />
                <apex:inputfield value="{!Managment__c.Date_of_Joining__c}" />
                <apex:inputfield value="{!Managment__c.Designation__c}" />

                <apex:inputfield value="{!Managment__c.Qualification__c }" style="width:220px;height:150px" />
            </apex:pageBlockSection>
        </apex:pageBlock>

        <apex:outputPanel layout="block">
            <table>
                <tr style="position: fixed; bottom: 0" align="center">
                    <td>
                        <apex:commandButton value="Save and Close" action="{!SaveandClose}" immediate="true" />
                    </td>
                </tr>
            </table>
        </apex:outputPanel>

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

My Extension code:

public with sharing class Management_Ext1 {
         private Managment__c  ManageSingleRecord;
         public string recordtype{get;set;}

         public String selectedRecordTypeValue{ get; set; }
         public String selectedDesignationValue{ get; set; }
          public Management_Ext1 (ApexPages.StandardController stdCtrl) 
    {

            this.ManageSingleRecord =   (Managment__c)stdCtrl.getRecord();

        if(this.ManageSingleRecord != null && this.ManageSingleRecord .Id != null)        
        {
              this.ManageSingleRecord = [   SELECT  Name,email__c,isClassTeacher__c,Qualification__c,Date_of_Joining__c from Managment__c
                                        WHERE   Id = : ManageSingleRecord.Id];       
        }
        else
        {
            this.ManageSingleRecord = new Managment__c();
        }   
     }

public List<selectoption> getRecordTypeValues() {
List< selectOption> ls= new list<selectOption>();
ls.add(new selectOption('', '- None -'));
for(Recordtype p:[select id,name from Recordtype where SobjectType='Managment__c']){
ls.add(new selectOption(p.id,p.name));
}
return ls;
}


public pageReference SaveandClose()
    {
        try{
            upsert this.ManageSingleRecord;
        }        
        catch(Exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.ERROR,'Error creating/updating record'));
        }
        PageReference pageRef = new PageReference('/t');
        pageRef.setRedirect(true);

        return pageRef;   
    }

    }
  • 1
    With your current code, when you change the recordtype selection, are you seeing the change reflected inside <apex:outputpanel id="one"> ? – Shane Steinfeld Oct 4 '18 at 20:48
0

You use management__c quite a bit in your VF which is the record provided by the standard controller but in your apex code you create ManageSingleRecord. I think if you change your VF page to use the variable in your extension instead of the variable provided by the standard controller you'll see more success. The standard VF field binding honors record type (I've seen this many times) so what you're doing should work. Lastly, in your else statement new Managment__c() make sure you set a default record type or the list will show all possible values.

If you're still having trouble rather then setting the record type directly into the field the way you are, pass the recordtypeId to apex and set the record type in your object on the backend.

  • Can you please show me how it works for this samle code – shaik shahin2786 Oct 12 '18 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.