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 a RecordType Id by Name without SOQL?

Sometimes in apex we required RecordType Id of an object by its Name. So, here is an example how we can find RecordType Id by Name.

In below example BankAccount__c is the custom object and “Savings Account” is one of the RecordType Name of BankAccount__c object. Now without SOQL I’ve to find “Savings Account” RecordType Id.

String recordTypeName = 'Savings Account';
Schema.SObjectType.BankAccount__c.getRecordTypeInfosByName().get(recordTypeName).getRecordTypeId();

Display all the fields of a sObject using Apex & Visualforce Page

Apex Code:

public class  DisplayAllFieldsClass {
 
     public map<string,schema.sobjectfield> data {get;set;}
   
     public  DisplayAllFieldsClass (){
         data = Schema.SObjectType.BISWAJEET__Student__c.fields.getMap();
     }
}

Visualforce Page Code:

<apex:page doctype="html-5.0" showheader="false" controller="DisplayAllFieldsClass">
    <apex:datatable value="{!data}" var="d">
             <apex:column headervalue="Field Name">
                 {!d}
             </apex:column>         
         </apex:datatable>
</apex:page>

How to include one visualforce page within another?

<apex:page sidebar="false" id="TestPage">
    <p>Inner Visualforce Page Before</p>
        <apex:include pagename="TestChart"></apex:include>
    <p>Inner Visualforce Page After</p>
</apex:page>

Note: Here in above sample visualforce page “TestPage” is the main page and “TestChart” is another visulaforce page within “Testpage”.