anusha(salesforce developer)

Monday, 20 March 2017

Example code for Action support?

<apex:page controller="AccountSearch">
    <apex:form >
        <apex:pageBlock >
            <apex:outputPanel >
                Enter account Name: <apex:inputtext value="{!name}"/>
                <apex:actionsupport event="onclick" action="{!search}" rerender="out"/>
            </apex:outputPanel>    
            <apex:outputPanel id="out">
                <apex:pageBlockTable value="{!conlist}" var="c">
                    <apex:column value="{!c.name}"/>
                </apex:pageBlockTable>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>



=============

public class AccountSearch {

    public string name {get;set;}
    public List<Contact> conlist{get;set;}
    
    public void search(){
    
        conlist= new list<contact>();
        
        conlist=[select id, name,phone from contact where account.name=: name];
    }
    
}

Example code for Action function ?

<apex:page controller="AccountSearch">
    <script>
         function javascriptfn(){
             alert('shall i Process');
             actionfun();// actionfunction name
         }
    </script>
    <apex:form >
        <apex:actionfunction name="actionfun" action="{!search}" rerender="out"/>
        <apex:pageBlock >
            <apex:outputPanel onclick="javascriptfn()">
                Enter account Name: <apex:inputtext value="{!name}"/>
                
            </apex:outputPanel>    
            <apex:outputPanel id="out">
                <apex:pageBlockTable value="{!conlist}" var="c">
                    <apex:column value="{!c.name}"/>
                </apex:pageBlockTable>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>