You need to sign in to do that
Don't have an account?
Harjeet Singh
How to display columns from 2 object in a sinle vf page
Hi All,
I need to display 3columns records as shown below in attached snap
Here "Subscription Name" and "Status" field/column are from same object called "Subscription" API name "csord__Subscription__c" and one field"Billing Account Number"(API Name-Billing_Account_Number__c) is from other object called "Service" API name "csord__Service__c".
Currently i am able to display fields/columns from Subscription object but not able to display the Biiling account number field from Service object.
I am attaching my VF and controllers codes as;
Note-"Subscription" object is master and "Service" is child.
please help me out and fine tune the code wherever possible.
I nee dto resolve this asap.
I need to display 3columns records as shown below in attached snap
Here "Subscription Name" and "Status" field/column are from same object called "Subscription" API name "csord__Subscription__c" and one field"Billing Account Number"(API Name-Billing_Account_Number__c) is from other object called "Service" API name "csord__Service__c".
Currently i am able to display fields/columns from Subscription object but not able to display the Biiling account number field from Service object.
I am attaching my VF and controllers codes as;
public class ControllerWrapper{ private Set<Id> selectedContactIds; //Our collection of the class/wrapper objects public List<wrapSubscription> wrapSubscriptionList {get; set;} public List<csord__Subscription__c> selectedSubscriptions{get;set;} public Boolean isCancel{get;set;} public string accountid; public String selectedActions{get;set;} public Date dat {get;set;} //Constructor class public ControllerWrapper(){ accountid=ApexPages.currentPage().getParameters().get('id'); if(wrapSubscriptionList == null) { wrapSubscriptionList= new List<wrapSubscription>(); for(csord__Subscription__c s: [select Id, Name,csord__Status__c, csord__Account__c from csord__Subscription__c where csord__Account__c=:accountid LIMIT 20]) { // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList wrapSubscriptionList.add(new wrapSubscription(s)); } } } public List<SelectOption> getActionsOptions() { List<SelectOption> actionOptions = new List<SelectOption>(); actionOptions.add(new SelectOption('','-None-')); actionOptions.add(new SelectOption('Take Over','Take Over')); actionOptions.add(new SelectOption('Invoice Switch','Invoice Switch')); actionOptions.add(new SelectOption('Move','Move')); /*countryOptions.add(new SelectOption('Germany','Germany')); countryOptions.add(new SelectOption('Ireland','Ireland'));*/ return actionOptions; } public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [select Id, Name,csord__Status__c, csord__Account__c from csord__Subscription__c where csord__Account__c=:accountid ])); } return setCon; } set; } public List<csord__Subscription__c > getWrapSubscriptionList() { setCon.setpagesize(20); setCon.setpageNumber(1); return (List<csord__Subscription__c >) setCon.getRecords(); } //Method for obtaining current page no. public Integer getPageNumber(){ return this.setCon.getPageNumber(); } //Function returns the total no pages Public Integer getTotalPages(){ Decimal totalSize = this.setCon.getResultSize(); Decimal pageSize = this.setCon.getPageSize(); Decimal pages = totalSize/pageSize; return (Integer)pages.round(System.RoundingMode.CEILING); } //Function to call Proceed button public void processSelected() { selectedSubscriptions = new List<csord__Subscription__c>(); for(wrapSubscription wrapSubscriptionObj : wrapSubscriptionList) { if(wrapSubscriptionObj.selected == true) { selectedSubscriptions.add(wrapSubscriptionObj.sub); } } } //Function to process the Cancel Button public PageReference cancel(){ return new PageReference('/'+accountid); } //Method for calling Next Button public void next(){ if(this.setCon.getHasNext()) this.setCon.next(); } //Method for calling Previous Button public void previous(){ if(this.setCon.getHasPrevious()) this.setCon.previous(); } // This is our wrapper/container class. In this example a wrapper class contains both the custom object Subscription and a Boolean value public class wrapSubscription { public csord__Subscription__c sub {get; set;} public Boolean selected {get; set;} public wrapSubscription(csord__Subscription__c s) { sub = s; selected = false; } } }
<apex:page docType="html-5.0" controller="ControllerWrapper" sidebar="false" showHeader="false"> <script type="text/javascript"> function selectAllCheckboxes(obj,receivedInputID){ var inputCheckBox = document.getElementsByTagName("input"); for(var i=0; i<inputCheckBox.length; i++){ if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){ inputCheckBox[i].checked = obj.checked; } } } </script> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:pageBlockSectionItem > <!-- <apex:outputText value="{!selectedActions}" label="You have selected:"/>--> <!--<apex:outputText label="Select the Action:"/>--> Select the Action: <!--<apex:outputPanel>--> <apex:selectList value="{!selectedActions}" multiselect="false" size="1"> <apex:selectOption itemValue="Take Over" itemLabel="Take Over"/> <apex:selectOption itemValue="Invoice Switch" itemLabel="Invoice Switch"/> <apex:selectOption itemValue="Move" itemLabel="Move"/> </apex:selectList> <!--</apex:outputPanel>--> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:PageBlockSection > <apex:pageBlockSectionItem > Date: <apex:input type="date" value="{!dat}" required="true" /> </apex:pageBlockSectionItem> <!--<apex:input value="{!myDate}" id="theTextInput" type="date"/>--> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Select Subscription" > <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Proceed " action="{!processSelected}" /> <apex:commandButton value="Cancel" action="{!cancel}" immediate="true" /> </apex:pageBlockButtons> <apex:pageblockSection title="Subscriptions" collapsible="false" columns="1" > <apex:pageBlockTable value="{!wrapSubscriptionList}" var="subWrap"> <apex:column > <apex:facet name="header"> <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')" /> </apex:facet> <!--<apex:inputCheckbox value="{!subWrap.selected}" id="inputId"/>--> <apex:inputCheckbox value="{!subWrap.selected}" id="inputId" disabled="{!NOT(subWrap.sub.csord__Status__c=='Active')}" /> </apex:column> <!--<apex:column value="{!subWrap.sub.Name}" />--> <apex:column headerValue="Subscription Name" > <!--<apex:commandLink value="{!subWrap.sub.Name}" action="/{!subWrap.sub.Id}"/>--> <apex:outputLink value="/{!subWrap.sub.Id}" target="_blank"> {!subWrap.sub.Name} </apex:outputLink> </apex:column> <apex:column value="{!subWrap.sub.csord__Status__c}" /> <apex:column value="{!subWrap.sub.csord__Account__c}" /> </apex:pageBlockTable> </apex:pageblockSection> <apex:commandButton rendered="{!setCon.hasPrevious}" value="first" action="{!setCon.first}"/> <apex:commandButton rendered="{!setCon.hasPrevious}" value="Previous" action="{!setCon.previous}"/> <apex:outputLabel value=" (page {!pageNumber} of {!totalPages})"/> <apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) < setCon.ResultSize}" value="{!setCon.pageNumber * setCon.pageSize} Of {!setCon.ResultSize}"></apex:outputText> <apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) >= setCon.ResultSize}" value="{!setCon.ResultSize} Of {!setCon.ResultSize}"></apex:outputText> <apex:commandButton rendered="{!setCon.hasNext}" value="next" action="{!setCon.next}"/> <apex:commandButton rendered="{!setCon.hasNext}" value="last" action="{!setCon.last}"/> <apex:pageBlock /> <apex:pageblockSection title="Selected Subscriptions" collapsible="false" columns="1" > <apex:pageBlockTable value="{!selectedSubscriptions}" var="c" id="table2" title="Selected Subscriptions" width="100%"> <!--<apex:column value="{!c.Name}" headerValue="Subscription Name"/>--> <apex:column headerValue="Subscription Name" > <apex:commandLink value="{!c.Name}" action="/{!c.Id}" target="_blank"/> </apex:column> <apex:column value="{!c.csord__Status__c}" headerValue="Status"/> <apex:column value="{!c.csord__Account__c}" headerValue="Account"/> </apex:pageBlockTable> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
Note-"Subscription" object is master and "Service" is child.
please help me out and fine tune the code wherever possible.
I nee dto resolve this asap.
Step1:
public subsbillingwrapper {
public csord__Service__c serviceObject{get;set;}
public csord__Subscription__c subsObject {get;set;}
public subsbillingwrapper (csord__Service__c ser, csord__Subscription__c subs ){
this.serviceObject=ser;
this.subsObject =subs ;
}
}
step 2:
get your data from child object like -
Map<id,list<csord__Service__c> > mapSubService= new Map<id,list<csord__Service__c >>(); {this Id is master Id(SubScription) and corresponding service records(child))
load the data into map
step 3: loop the master data and get the corrosponding the child records..
lstwrappe= new list<subsbillingwrapper >();
for( csord__Subscription__c asub;[SOQL]){
for( csord__Service__c ser : mapSubService.get(asub.id) ){
// pass into the wrapper..
lstwrappe.add(new subsbillingwrapper (ser ,asub) );
}
}
use the wrapper in vf page..
Thanks for your valuable inputs .
I tried to implement what you said but didnt succeeded.I am fresher in salesforce.
I request you please twik my code according to your understanding as i need to resolve this asap due to my urgent requiremnt.
Many thanks in advance