+ Start a Discussion
nbknbk 

How to hide page block section

Hi Everybody,

 

My visualforce page having 2 sections(Account and Contacts). If the Account having any contacts need to display Contacts section other wise display only Account section.

 

Used following statement in VFP, but contacts section visible even no records exists on Contact object to corresponding Account Id

<apexageblockSection columns="5" Title="Contacts" rendered="{!NOT(ISNULL(contactsLst))}">

 

 

Can you please share your ideas.

 

Thanks,

Krishna

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.

All Answers

Prafull G.Prafull G.

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.

This was selected as the best answer
sfdcfoxsfdcfox

You may also use:

 

 

<apex:pageBlockSection rendered="{!NOT(contactsLst.empty)}">

 

 

salesforcemicky125salesforcemicky125

crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.



crmtech21 wrote:

Hi Krishna,

 

Instead of check NULL for the contact list, try using the list size.

something like

 

<apex:pageBlockSection  rendered="{!IF(contactsLst.size>0, true, false)}">

 

Regards,

Prafull G.


Hi,

 

I have  2 Page Blocks in my Visualforce page.

 

1) In which i will give Email as input text  for searching any record is there in the  Data base with that Email Address  if there a  record found in DB then it will pull the record and Display it in the VF Page.

 

On fetching the record with the Email Address i want  to Hide/Display 2nd Page  block section.

 

In 2nd PageB lock Section we have fields like Name, Email, First Name, Last Name to create a New Contact record and Email as Unique record to fetch the Record details from the Data BAse.

 

2) When a user gives Email Address and Search for a Record in the data base using the Email  as input text if there is NoRecord found in the DataBase i want to See the Page Block section where User can give the Input for creating the New Conatct Record.

 

 

can anyone provide me sample Example for this................

 

I can able to fetch the Record using  the Email Address  and when i fetch the record i can see the Form page which i don't want to see when the record is found in the Data BAse . I want to hide it when a matching record is found with the Email Address

 

 

This is my Controller

 

public class attendeecheckincontroller

{

    public id contactid{get;set;}

    public Boolean displaySearchResults{get;set;}

    public Boolean displayRegistration{get;set;}

    public Boolean displaypblock{get;set;}

    public String inputemail {get;set;}

    Set<Id> sObjectIds = new Set<Id>();

    Set<id> sObjectrecIds = new Set<id>();

    public List<Event_Registration__c> ObjEvent{get;set;}

    public List<Recruiting_Event__c> ObjRecEvent{get;set;}

    public List<Contact> objContact {get;set;}

    public Contact con{get; set;}

    public Boolean displayPopup {get;set;}

    public attendeecheckincontroller(ApexPages.StandardController controller) {

    displaySearchResults = false;

    displayRegistration = true;

    displaypblock = true;

    displayPopup = false;

    con=new Contact ();

    }

     public void showPopup()

    {  

    displayPopup = true;

    }

public void closePopup() {

        displayPopup = false;

     }

public PageReference search()

    {displaypblock = true;

       try

       {

      

     List<Contact> objContact = new List<Contact>();

     objContact = [select id,name,FirstName,LastName,MobilePhone,Email from Contact  where email= :inputemail limit 1];

     for(Event_Registration__c e:[select id,Name,Contact__c,Recruiting_Event__c,Attending__c,Attended__c,Invited__c,No_Response__c,No_Show__c,UserResponse__c from Event_Registration__c where Contact__c=:ObjContact[0].id  and Attended__c=False limit 10])

     {

         sObjectIds.add(e.id);

         sObjectrecIds.add(e.Recruiting_Event__c);

      }

        ObjEvent=[Select id,Name,Contact__c,Recruiting_Event__c,Attended__c  from Event_Registration__c where id =:sObjectIds order by id limit 10];

        ObjRecEvent=[Select id,Campus_Contact__c,Location__c,Type__c,End_Date__c,Start_Date__c,Class__c,Name,Year_FY__c,Time__c,Team__c,System_ID__c,Status__c,Season__c,Room__c,Recruiting_Event_ID__c,Program__c,Practitioner_Event_Lead__c,Post_Event_Notes__c,Description__c from  Recruiting_Event__c where id=:sObjectrecIds order by id limit 10];

           if(ObjEvent.size()>0){

                displaySearchResults=true;

                displayRegistration=true;

                           }

            else{

                 displaySearchResults=false;

                 displayRegistration=true;

                }

       inputemail ='';

       sObjectIds.clear();

       sObjectrecIds.clear();

       }

       catch(Exception ex){

          System.debug('\n\nException ='+ex.getMessage()+'\n\n');

          sObjectIds.clear();

       }

       return null;

    }

public PageReference redirectPopup()

    {

    displayPopup = false;

       try

   {

   PageReference p=new Pagereference('/event/checkin');

         p.setRedirect(true);

    ObjEvent[0].Attended__C = true;

    update ObjEvent;

    return p;

   }

   catch(Exception e){

   ApexPages.addMessages(e);

    return null;

   }

       

    }

public void cancel(){}

public pagereference Save()

    {

    insert con;

    con=new Contact ();

    PageReference pr=new PageReference('/event/attendeecheckin');

        pr.setRedirect(true);

        return pr;

    }

  }

 

 

VF Page:

 


<apex:page standardController="Event_Registration__c" extensions="attendeecheckincontroller" showHeader="False" sidebar="false">

<apex:form >


<table><tr><td></td></tr><tr><td>Provide Your Email Address</td><td><apex:inputText id="inputemail" value="{!inputemail}"/></td><td><apex:commandButton value="Search" action="{!search}" reRender="searchResults,displaySearchResults"></apex:commandButton></td></tr></table>

<apex:pageblock rendered="{!displaypblock}">
<apex:outputpanel id="searchResults">
<table width="100%"><tr><td width="80%"><apex:pageBlockTable rendered="{!displaySearchResults}" id="diTable" value="{!ObjRecEvent}" var="idat" border="1" cellspacing="2px" width="100%" headerClass="he1" cellpadding="6px" columnsWidth="150px,150px,150px,150px,150px,150px" rowclasses="oddrows,evenrows">

<apex:column headerValue="Recuring Event Name" ><apex:outputField value="{!idat.Name}" rendered="{!IF(ISBLANK(idat.Name), 'false', 'true')}"/>
</apex:column>
<apex:column headerValue="Campus Contact" ><apex:outputField value="{!idat.Campus_Contact__c}" rendered="{!IF(ISBLANK(idat.Campus_Contact__c), 'false', 'true')}"/>
</apex:column>
<apex:column headerValue="Location">
<apex:outputField value="{!idat.Location__c}" rendered="{!IF(ISBLANK(idat.Location__c), 'false', 'true')}"/>
</apex:column>
<apex:column headerValue="Season">
<apex:outputField value="{!idat.Season__c}" rendered="{!IF(ISBLANK(idat.Season__c), 'false', 'true')}"/>
</apex:column>
<apex:column headerValue="Room">
<apex:outputField value="{!idat.Room__c}" rendered="{!IF(ISBLANK(idat.Room__c), 'false', 'true')}"/>
</apex:column>
<apex:column headerValue="Status">
<apex:outputField value="{!idat.Status__c}" rendered="{!IF(ISBLANK(idat.Status__c), 'false', 'true')}"/>
</apex:column>
<apex:column headerValue="Start Date">
<apex:outputField value="{!idat.Start_Date__c}" rendered="{!IF(ISBLANK(idat.Start_Date__c), 'false', 'true')}"/>
</apex:column>
<apex:column headerValue="End Date">
<apex:outputField value="{!idat.End_Date__c}" rendered="{!IF(ISBLANK(idat.End_Date__c), 'false', 'true')}"/>
</apex:column><apex:column ><apex:commandButton ></apex:commandbutton></apex:column>

</apex:pageBlockTable></td><td width="20%"><apex:pageBlockTable rendered="{!displaySearchResults}" id="dTable" value="{!ObjEvent}" var="dat" border="1" cellspacing="2px" width="100%" headerClass="he1" cellpadding="6px" columnsWidth="150px,150px,150px,150px,150px,150px" rowclasses="oddrows,evenrows">
<apex:column headerValue="Attended"><apex:commandButton value="Attended" action="{!showPopup}" rerender="searchResults" status="status">
</apex:commandButton>
<apex:outputPanel id="popup" title="Confirmation">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel id="popInnerOutputPnl1" styleClass="customPopup" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel id="popInnerOutputPnl" styleClass="customPopup" layout="block" rendered="{!displayPopUp}">
<table class="contentContainer" id="Container"><tr><td></td></tr></table>
<table width="50%"><tr><td>
<apex:commandButton value="Cancel" title="Cancel" action="{!closePopup}" styleClass="closeButton" rerender="popup"></apex:commandButton>
<apex:commandButton value="Confirm" action="{!redirectPopup}" styleClass="closeButton" rerender="popup"></apex:commandButton></td></tr></table>
</apex:outputPanel>
</apex:outputPanel></apex:column>
</apex:pageBlockTable>
</td></tr><tr><td> </td></tr></table>

</apex:outputpanel>

</apex:pageblock>

</apex:form><apex:form ><apex:pageBlock ><apex:outputPanel rendered="true"> <table id="contactInfoTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr><td width="160" vAlign="top">Title:</td><td vAlign="top"><apex:inputField taborderhint="1" value="{!con.Title}" /></td></tr>
<tr><td width="160" vAlign="top">First Name:*</td><td vAlign="top"><apex:inputField taborderhint="2" value="{!con.FirstName}" id="first_name"/></td></tr>
<tr><td width="160" vAlign="top">Last Name:*</td><td vAlign="top"><apex:inputField taborderhint="3" value="{!con.LastName}"/></td></tr>
<tr><td width="160" vAlign="top">Phone number:*</td><td vAlign="top"><apex:inputField taborderhint="4" value="{!con.Phone}"/></td></tr>
<tr><td width="160" vAlign="top">Email address:*</td><td vAlign="top"><apex:inputField taborderhint="5" value="{!con.Email}"/></td></tr>
<tr><td></td><td></td></tr>
<tr><td width="160" vAlign="top"><apex:commandButton value="Register" action="{!Save}" rerender="out, in" status="status" styleclass="buttonFormPrimary"/></td><td></td></tr>
</tbody>
</table></apex:outputPanel></apex:pageBlock></apex:form> </div></div></div>
<style type="text/css">
.customPopup {
background-color: white;
border-width: 1px;
color:gray;
border-style: solid;
z-index: 9999;
left: 50%;
padding:10px;
position: absolute;
/* These are the 3 css properties you will need to change so the popup
displays in the center of the screen. First set the width. Then set
margin-left to negative half of what the width is. You can add
the height property for a fixed size pop up if you want.*/
width: 500px;
margin-left: -250px;
top:200px;
}
.popupBackground{
background-color:black;
opacity: 0.40;
filter: alpha(opacity = 40);
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 9998;
}

.closeButton {
float: right;
}
</style>
</apex:page>