Monday 18 March 2013

onChange of Pick list value Another Page block section should be Rendered

Hi,
 Create VF page , i.e onChange of pick list value Stage to 'closed lost' Another page block section should visible, if you select another stage value it should be hide.

See the code below,

  <apex:page standardController="Opportunity" sidebar="false">
    <apex:sectionHeader title="Edit Opportunity" subtitle="{!opportunity.name}"/>
    <apex:form >
        <apex:pageBlock title="Edit Opportunity" id="thePageBlock" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>                
            </apex:pageBlockButtons>
            <apex:actionRegion >
                <apex:pageBlockSection title="Basic Information" columns="1">
                    <apex:inputField value="{!opportunity.name}"/>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Stage"/>
                        <apex:outputPanel >
                            <apex:inputField value="{!opportunity.stageName}">
                                <apex:actionSupport event="onchange" rerender="thePageBlock"
                                                    status="status"/>
                            </apex:inputField>
                            <apex:actionStatus startText="applying value..." id="status"/>
                        </apex:outputPanel>
                    </apex:pageBlockSectionItem>
                    <apex:inputField value="{!opportunity.amount}"/>
                    
                </apex:pageBlockSection>
            </apex:actionRegion>

 <!-- This is another page block section , it visible when stage is 'closed lost' --> 
            <apex:pageBlockSection title="Closed Lost Information" columns="1"
                                   rendered="{!opportunity.stageName == 'Closed Lost'}">
                <apex:inputField value="{!opportunity.closedate}"/>
                <apex:inputField value="{!opportunity.amount}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Display Duplicate Records count

Here We have a scenario.

In Account object we have lot of records. If we need to know , how many  records with the same name present in your object.

Record Name and that record count..

Please look at this code.

Vf Page:-
----------

<apex:page controller="test4">
 <apex:pageblock title="Map Usage On VF">
     <apex:pageBlockTable value="{!data}" var="d">
         <apex:column headerValue="Account Name">
             {!d}
         </apex:column>
         <apex:column headerValue="Duplicate Count">
             {!data[d]}
         </apex:column>
     </apex:pageBlockTable>
 </apex:pageblock>
</apex:page>


Controller
------------

public class test4{
 
    public map<string,integer> data {get;set;}
    public test4(){
        data = new map<string,integer>();
        for(Account acc: [Select Id, Name, (Select Id, Name, Email from Contacts), Phone from Account]){
            integer count = data.get(acc.name);
            if(count != null)
                count++;
            else
                count = 1;
            data.put(acc.name, count);
        }
    }
}