Play Games

Search This Blog

Wednesday, November 25, 2015

LEFT function in Visualforce Page

Assume "00128000003yhTi" is the AccountId in my instance.
It has one contact with name "swetha Singh".
Without Left function:
Visualforce Page:
<apex:page standardController="Account">
    <apex:pageBlock title="Account associated Contacts(Display First Word of Contact)">
        <apex:pageBlockTable value="{!account.Contacts}" var="item">
            <apex:column value="{!item.name}" headerValue="Contact Name" />
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Output: When you run the page with url like this "https://c.ap2.visual.force.com/apex/LeftFunction?id=00128000003yhTi"
With Left Function:
Visualforce Page :
<apex:page standardController="Account">
    <apex:pageBlock title="Account associated Contacts(Display First Word of Contact)">
        <apex:pageBlockTable value="{!account.Contacts}" var="item">
            <apex:variable value="{!FIND(' ',item.name)}" var="position"/>
            <apex:variable value="{!item.name}" var="test"/>
            <apex:column value="{!IF(position >0 ,LEFT(test,position-1),test)}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Output: When you run the page with url like this "https://c.ap2.visual.force.com/apex/LeftFunction?id=00128000003yhTi"

No comments:

Post a Comment