Author Archives: Biswajeet

About Biswajeet

Biswajeet is my Name, Success is my Aim and Challenge is my Game. Risk & Riding is my Passion and Hard Work is my Occupation. Love is my Friend, Perfection is my Habit and Smartness is my Style. Smiling is my Hobby, Politeness is my Policy and Confidence is my Power.

How to get picklist values based on record type in Visualforce page?

Here in below example I’ve a custom object “Customer__c”, which has two record types “HR” and “Marketing”.

Apex Class:

public with sharing class recordTypeSample{

    public String selectedRT {get;set;}
    public List<SelectOption> recordTypeList {get;set;}
    public Customer__c customer {get;set;}
    
    public recordTypeSample(){
    
        customer = new Customer__c();
        recordTypeList = new List<SelectOption>();
        getRecordTypeList();
    
    }
    
    public void getRecordTypeList(){
         
        List<RecordType> rtList = [SELECT Id,Name FROM RecordType WHERE SObjectType='Customer__c'];
        recordTypeList.add(new SelectOption('--None--', '--None--'));
        for(RecordType rt : rtList)
        {
            recordTypeList.add(new SelectOption(rt.Id, rt.Name));
        }
    }
    
     public void getPickListValues(){
     
        if(selectedRT != null){
            customer = new Customer__c(RecordTypeId = selectedRT);
        }
    }
}

Visualforce Page:

<apex:page controller="recordTypeSample">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:selectList value="{!selectedRT}" size="1" multiselect="false" label="Record Type" title="Record Type" id="recordTypes"> 
                    <apex:actionSupport event="onchange" action="{!getPickListValues}" reRender="categoryPicList" />
                    <apex:selectOptions   value="{!RecordTypeList}" /> 
                </apex:selectList>
                <apex:inputField id="categoryPicList" value="{!customer.Category__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

HR Record Type Picklist :

Marketing Record Type Picklist :

Query Validation Rules associated with an Object using REST API

/services/data/v39.0/tooling/query?q=Select Id,ValidationName,Active,Description,EntityDefinition.DeveloperName,ErrorDisplayField, ErrorMessage From ValidationRule WHERE EntityDefinition.DeveloperName = 'Account'

Radio Button in Visualforce Page

<apex:page >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >Gender
                    <apex:selectRadio >
                        <apex:selectOption itemLabel="Male" itemValue="m"/>
                        <apex:selectOption itemLabel="Female" itemValue="f"/>           
                    </apex:selectRadio>     
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>