Activity Forums Salesforce® Discussions pageblockSection is not rendered on click of commandButton

  • pageblockSection is not rendered on click of commandButton

    Posted by saloni gupta on July 28, 2017 at 1:13 pm

    I want to show the description of account on click of name

    VF page;-

    <apex:page controller="SearchAccountCon" tabStyle="account">
    <apex:form >
    <apex:inputText value="{!searchString}" label="Search"/>
    <apex:commandButton value="search" action="{!search}"/>
    </apex:form>
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockTable value="{!acct}" var="a" >
    <apex:column >
    <apex:commandLink value="{!a.Name}" action="{!showdetails}" rerender="RID" >
    </apex:commandLink>
    <apex:pageBlock id="RID">
    <apex:pageBlockTable value="{!acct}" var="b" rendered="{!showSection1}">
    <apex:column value="{!b.description}"/>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:column>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
    </apex:page>

    apex class;

    public class SearchAccountCon {
    public static String searchString {get; set; }
    public Boolean showSection1{get;set;}
    public static String Id {get; set; }
    public static List<Account> acct{get;set;}
    public String showleadid { get; set; }

    public SearchAccountCon(){
    showSection1 = false;
    }

    public static void search(){
    try{
    acct= Database.query('Select Name, description,(select LastName From Contacts) From Account WHERE Name LIKE \'%'+searchString+'%\' Limit 100');
    system.debug('ddd'+acct);
    }
    catch(Exception e){
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account site'));
    }
    }

    public void showdetails() {
    if(showSection1== true){
    showSection1= false;
    }else{
    showSection1= true;
    }
    }}

    Aman replied 7 years, 3 months ago 2 Members · 1 Reply
  • 1 Reply
  • Aman

    Member
    August 8, 2017 at 12:38 pm

    Hello Saloni,

    You can try  this :

    VF page;-

    <apex:page controller="SearchAccountCon" tabStyle="Account">
    <apex:form >

    <apex:inputText value="{!searchString}" />
    <apex:commandButton value="search" action="{!search}" rerender="pageblId"/>

    <apex:pageBlock >
    <apex:pageBlockTable value="{!acct}" var="acc" id ="pageblId">
    <apex:column headerValue="Acccount Name" >
    <apex:commandLink value="{!acc.name}" action="{!getCont}" reRender="LinkId" >
    <apex:param value="{!acc.Id}" name="LinkCont" assignTo="{!SearchId}"/>
    </apex:commandLink>
    </apex:column>
    <apex:column >
    <apex:pageBlockTable value="{!cont}" var="con" id="LinkId">
    <apex:column value="{!con.LastName}"/>
    <apex:column value="{!con.id}"/>
    </apex:pageBlockTable>
    </apex:column>

    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
    </apex:page>

    Apex class :

    public class SearchAccountCon {
    public String SearchId{get;set;}
    public String searchString {get; set; }
    public List<Account> acct{get;set;}
    public List<contact> cont{get;set;}
    public void search(){

    acct= Database.query('Select Name, description From Account WHERE Name LIKE \'%'+searchString+'%\' Limit 100');
    cont = new List<contact>();

    }
    public void getCont(){
    cont=[select id,LastName,accountId from contact where accountID =:SearchId];
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos