function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
arunadeveloperarunadeveloper 

Display pageBlocks based on object name

Hi There,

 

I am developing a visual force page which will have page blocks sections for 2 different objects

example TestObj1__c is one object TestObj2__c is another object.

TestObj1__c is master details relationship to TestObj2__c.

so on visulaforce page i need to display both TestObj1__c  or TestObj2__c.

so how can I render a page block based on object names 

 

if i click a custom button from TestObj1__c it should only display TestObject1__c contacts 

If i click the custom button from TestObject2__c it should only display TestObject2__c Contacts.

 

Can anyone please suggest how to do this  ? any an idea ?

 

Satish_SFDCSatish_SFDC

Yes,

I think this can be done using a custom controller. However, i would like to have some information.

 

1. You said that if a custom button on TestObj1__c is clicked, it should display the 'contacts' related to TestObject1__c. How is the Contacts Objects related to the objects-TestObj1 and TestObj2? Please let me know the relationship between all these objects.

 

I assume that contacts is the child object to the TestObjects. If that is the case, we can pass a unique value as a parameter to the visualforce page and then identify the type of the object in the visualforce page. Based upon the type of the object identified, we can then render or not render the pageblock.

 

Regards,

Satish Kumar

 

 

arunadeveloperarunadeveloper
Yes that is true contact is look up to both the test objects. And and also I have 2 types of contacts.
Like broker and customer.so customer contacts and broker contacts should be displayed ob TestObj--c and only customer contacts on Test2Obj--c.
Can you please provide me the solution.
Has I have to complete the task as soon as possible.
souvik9086souvik9086

Hi,

 

You can write a custom controller and use rendered attribute for the pageblocktables.

 

In Controller

 

public class YourClassName{

public Boolean visibleObj1{get;set;}

public Boolean visibleObj2{get;set;}

 

public YourClassName(){

visibleObj1 = false;

visibleObj2 = false;

}

 

public void forObj1(){

//Your code for retrieving contact list

visibleObj1 = true;

visibleObj2 = false;

}

 

public void forObj2(){

//Your code for retrieving contact list

visibleObj1 = false;

visibleObj2 = true;

}

}

 

In VF Page

 

<apex:page controller="YourClassName">

<apex:form>

<apex:pageblock>

<apex:outputpanel rendered="{!visibleObj1 == true}">

<apex:pageblocktable value="YourList_OBJ1" var="YourVariableName">

<!-- Your Code -->

</apex:pageblocktable>

</apex:outputpanel>

<apex:outputpanel rendered="{!visibleObj2 == true}">

<apex:pageblocktable value="YourList_OBJ2" var="YourVariableName">

<!-- Your Code -->

</apex:pageblocktable>

</apex:outputpanel>

</apex:pageblock>

<apex:commandbutton action="{!forObj1}" value="Obj 1"/>

<apex:commandbutton action="{!forObj2}" value="Obj 2"/>

</apex:form>

</apex:page>

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

arunadeveloperarunadeveloper

well it's  not working , it hidding 2 blocks at a time or showing 2 blocks at a time.

do you have any other solutions

 

public withsharingclass NewContactRoleControllerExt{

 

publicstatic Boolean showBrokerContacts{get;set;}

 publicstatic Boolean showLocationContacts{get;set;}

 

publicNewContactRoleControllerExt(ApexPages.StandardController stdController){

 

showBrokerContacts=false;

showLocationContacts=false;

 

}

 

public staticlist<BrokerContactRoleWrapper> getEnrollmentEventBrokerContacts(){

 

list<Contact> EnrollmentEvenBrokerContactList =newlist<Contact>();

 

if(enrollmentEventBrokerAccountIdsSet()!=null){

EnrollmentEvenBrokerContactList=[select id,Name, Account.Name ,AccountId,Account.RecordTypeId fromContactwhere AccountId IN:enrollmentEventBrokerAccountIdsSet ()

 

andAccount.RecordTypeId=:brokerRecordTypeId];

 

}

system.debug('*******************EnrollmentEvenBrokerContactList='+EnrollmentEvenBrokerContactList);

 

if(EnrollmentEvenBrokerContactList.size()>0){

 

for(ContactconBroker : EnrollmentEvenBrokerContactList){

 

system.debug('*************in for loop conBroker='+conBroker);

brokerContactList.add(

newBrokerContactRoleWrapper(conBroker));

}

system.debug('*************in for loop brokerContactList='+brokerContactList);

}

//showCutomerContacts=true;

showBrokerContacts=true;

showLocationContacts=false;

 

returnbrokerContactList;

 

}

//Get enrollementeventlocation contacts

publicstaticlist<LocationContactRoleWrapper> getEnrolmentEventLocationContacts(){

 

list<Contact> enrolmentEventLocationContactList;

 

system.debug('*******************enrolmentEventLocationContacIds='+enrolmentEventLocationContacIdSet());

 

if(enrolmentEventLocationContacIdSet()!=null){

enrolmentEventLocationContactList=[

select id,Name, AccountId,Account.Name,Account.RecordTypeId fromContactwhere id IN : enrolmentEventLocationContacIdSet() andAccount.RecordTypeId=:customerRecordTypeId];

}

if(enrolmentEventLocationContactList.size()>0){

 

for(ContactlocationCon : enrolmentEventLocationContactList){

locationContactList.add(

newLocationContactRoleWrapper(locationCon));

}

}

showBrokerContacts=false;

showLocationContacts=true;

 

returnlocationContactList;

}

}

 

<apex:pageBlock rendered="{!showBrokerContacts==true}">

</apex:pageBlock>

<

apex:pageBlockrendered="{!showLocationContacts==true}">

</apex:pageBlock>

 

any other an idea

souvik9086souvik9086

It should show the rendered pagebloch according to the latest code. At first time loading it is hidden. Then after clicking one button what is coming?. Both becoming visible? Make sure that the whole page is not refreshing during the method call. 

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

arunadeveloperarunadeveloper

Actually when ever the page loaded first time it should display the pageblocks depends on the object.

 

Test1Obj__c is having custom button , when i click that button is should display contacts related to Test1Obj__ contacts. like for Test2Obj__c also.

 

 

souvik9086souvik9086

"Depends on the object" means by which basis? Where are you displaying the object when you first loaded the page. If you display the object anywhere then based on that value you can make the render of pageblock.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks