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
Lakshmi Kalyan KoduriLakshmi Kalyan Koduri 

Create a form which has NRI and Non-Nri and based on nri and non nri i need different type of address fields

Best Answer chosen by Lakshmi Kalyan Koduri
Khan AnasKhan Anas (Salesforce Developers) 
Hi Lakshmi,

Greetings to you!

Please try the below code, it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page standardController="Contact" extensions="HideSectionBasedOnPicklistC">
    <apex:form >
        <apex:pageBlock > 
            <apex:actionRegion >
                <apex:selectList value="{!pickchoice}" multiselect="false" size="1">
                    <apex:selectOptions value="{!items}"/>
                    <apex:actionSupport event="onchange" rerender="out1,out2"/>
                </apex:selectList>
            </apex:actionRegion>            
            <br/><br/>
            <apex:pageBlockSection id="out1" >
                <apex:outputPanel rendered="{!IF(pickchoice== 'NRI' && pickchoice!= 'None', true , false)}">                    
                    <apex:outputLabel value="First Name" /><br/>
                    <apex:inputField value="{!contact.FirstName}" /><br/><br/>
                    <apex:outputLabel value="Last Name" /><br/>
                    <apex:inputField value="{!contact.LastName}" />
                </apex:outputPanel>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection id="out2" >
                <apex:outputPanel rendered="{!IF(pickchoice== 'Non-NRI' && pickchoice!= 'None', true , false)}">
                    <apex:outputLabel value="Email" /><br/>
                    <apex:inputField value="{!contact.Email}" /><br/><br/>
                    <apex:outputLabel value="Phone" /><br/>
                    <apex:inputField value="{!contact.Phone}" />
                </apex:outputPanel>
            </apex:pageBlockSection>        
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class HideSectionBasedOnPicklistC {
    
    public String Pickchoice {get;set;}
    
     public HideSectionBasedOnPicklistC(ApexPages.StandardController controller) {

    }
    
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','None'));
        options.add(new SelectOption('NRI','NRI'));
        options.add(new SelectOption('Non-NRI','Non-NRI'));
        return options;
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Kalyan,

You can create a custom object and add all the fields which you need.

Now create two record types 
  • NRI
  • Non-NRI
Add the fields accordingly which you need to display for NRI and Non-NRI.

Based on the record type selected, the fields will be displayed.

Please let us know if you are looking for something else.

Thanks,
Nagendra

 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Lakshmi,

Greetings to you!

Please try the below code, it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page standardController="Contact" extensions="HideSectionBasedOnPicklistC">
    <apex:form >
        <apex:pageBlock > 
            <apex:actionRegion >
                <apex:selectList value="{!pickchoice}" multiselect="false" size="1">
                    <apex:selectOptions value="{!items}"/>
                    <apex:actionSupport event="onchange" rerender="out1,out2"/>
                </apex:selectList>
            </apex:actionRegion>            
            <br/><br/>
            <apex:pageBlockSection id="out1" >
                <apex:outputPanel rendered="{!IF(pickchoice== 'NRI' && pickchoice!= 'None', true , false)}">                    
                    <apex:outputLabel value="First Name" /><br/>
                    <apex:inputField value="{!contact.FirstName}" /><br/><br/>
                    <apex:outputLabel value="Last Name" /><br/>
                    <apex:inputField value="{!contact.LastName}" />
                </apex:outputPanel>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection id="out2" >
                <apex:outputPanel rendered="{!IF(pickchoice== 'Non-NRI' && pickchoice!= 'None', true , false)}">
                    <apex:outputLabel value="Email" /><br/>
                    <apex:inputField value="{!contact.Email}" /><br/><br/>
                    <apex:outputLabel value="Phone" /><br/>
                    <apex:inputField value="{!contact.Phone}" />
                </apex:outputPanel>
            </apex:pageBlockSection>        
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class HideSectionBasedOnPicklistC {
    
    public String Pickchoice {get;set;}
    
     public HideSectionBasedOnPicklistC(ApexPages.StandardController controller) {

    }
    
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','None'));
        options.add(new SelectOption('NRI','NRI'));
        options.add(new SelectOption('Non-NRI','Non-NRI'));
        return options;
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Lakshmi Kalyan KoduriLakshmi Kalyan Koduri
Thank you so much @ Khan Anas. It worked for me. Your work is really appreciable.