Friday, 26 September 2014

How to get help text in apex class ??

We generally use help text while creating custom field in salesforce . Sometimes we need it in apex controller while development. This post is regarding to get help text of particular field and display in vf page. 

Here is some code snippet to get help text in apex class.

Schema.DescribeFieldResult dfr = Schema.sObjectType.Account.fields.TestField__c;
String helptext = dfr.getSObjectField().getDescribe().getInlineHelpText();

In the visualforce page we can display help text.

{!$ObjectType.Account.fields.TestField__c.inlineHelpText}

Sunday, 14 September 2014

How to check list size in Visualforce page

Hi All,

It seems to very simple by name but not as much simple as you are thinking now.As we all know list itself has a method so called size() to check its size,however we can write list.size() in controller, which will return no. of elements present in the list otherwise return 0 if no elements present .But we can not write list.size method in visual-force page,then how will we check ????

For that I have done a workaround, one visual-force page is there having one field Account Type. When Account Type will be selected with some value ,then list of Accounts records will be displayed whose Account Type is matched with the selected value otherwise a message saying No Accounts Present in this Type.

Here is page:-

<apex:page controller="passingParamActionFuncController">
    <apex:form >
        <apex:pageBlock title="Account Information" id="pb">
            <apex:pageBlockSection >
                <apex:inputField value="{!account.Type}" Onchange="displayAccount();"/>
                <apex:actionFunction name="displayAccount" action="{!displayAccount}" reRender="panel,mess"/>
                <apex:outputPanel id="panel">
                    <apex:pageMessages id="mess"></apex:pageMessages>
                 
                        <apex:pageBlockTable value="{!listOfAccounts}" var="account" rendered="{! IF(ISBLANK(listOfAccounts), false, true) }">
                     
                            <apex:column value="{!account.Name}"/>
                            <apex:column value="{!account.Type}"/>
                        </apex:pageBlockTable>
                     
                    </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>

</apex:page>

And Controller
public with sharing class passingParamActionFuncController {

    public Account account { get; set; }
 
    public list<Account> listOfAccounts{get;set;}
 
    public passingParamActionFuncController(){
        account = new Account();
    }
 
    public PageReference displayAccount() {
        System.debug('Printing account-->'+account.Type);
        listOfAccounts = [SELECT id,Name,Type
                          FROM Account
                          WHERE Type =:account.Type];
                       
        if(listOfAccounts.size() == 0){
            Apexpages.addMessage(new ApexPages.message(ApexPages.Severity.Info,'No Accounts Present in this Type'));
        }
        return null;
    }

 
}