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
SFTerrSFTerr 

VF page to display selected record in list button

Hi, I’ve created custom list button, which when clicked open VF page. That button will be used for viewing existing records only (so user will have to select the record first from the list by checkbox and then clicking new button), but currently it opens up new page, but all fields are blank.
How do I change the apex to display the selected record instead (I've tried different options, e.g. with controller.getSelected, but can't get pass the errors)?

controller:
global with sharing class SalesInvoicePrintReceipt extends SkyEditor2.SkyEditorPageBaseWithSharing {
  
  public c2g__codaInvoice__c record {get{return (c2g__codaInvoice__c)mainRecord;}}
  public with sharing class CanvasException extends Exception {}

  
  

  public SalesInvoicePrintReceipt(ApexPages.StandardController controller) {
    super(controller);


    SObjectField f;

    f = c2g__codaInvoice__c.fields.c2g__Account__c;
    f = c2g__codaInvoice__c.fields.c2g__Opportunity__c;
    f = c2g__codaInvoice__c.fields.Name;
    f = c2g__codaInvoice__c.fields.c2g__InvoiceDate__c;

    List<RecordTypeInfo> recordTypes;
    try {
      mainSObjectType = c2g__codaInvoice__c.SObjectType;
      setPageReferenceFactory(new PageReferenceFactory());
      
      mainQuery = new SkyEditor2.Query('c2g__codaInvoice__c');
      mainQuery.addFieldAsOutput('c2g__Account__c');
      mainQuery.addFieldAsOutput('c2g__Opportunity__c');
      mainQuery.addFieldAsOutput('Name');
      mainQuery.addFieldAsOutput('c2g__InvoiceDate__c');
      mainQuery.addWhere('Id', mainRecord.Id, SkyEditor2.WhereOperator.Eq)
        .limitRecords(1);
      
      
      
      mode = SkyEditor2.LayoutMode.LayoutSalesforce; 
      
      queryMap = new Map<String, SkyEditor2.Query>();
      SkyEditor2.Query query;
      
      
      p_showHeader = true;
      p_sidebar = true;
      init();
      
      if (record.Id == null) {
        
        saveOldValues();
        
      }

      
      
    }  catch (SkyEditor2.Errors.FieldNotFoundException e) {
      fieldNotFound(e);
    } catch (SkyEditor2.Errors.RecordNotFoundException e) {
      recordNotFound(e);
    } catch (SkyEditor2.ExtenderException e) {
      e.setMessagesToPage();
    }
  }
  

  @TestVisible
    private void sObjectNotFound(SkyEditor2.Errors.SObjectNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }
  @TestVisible
    private void fieldNotFound(SkyEditor2.Errors.FieldNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }
  @TestVisible
    private void recordNotFound(SkyEditor2.Errors.RecordNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }

  with sharing class PageReferenceFactory implements SkyEditor2.PageReferenceFactory.Implementation {
    public PageReference newPageReference(String url) {
      return new PageReference(url);
    }
  }
}


Thanks
 
ManojjenaManojjena
Hi ,

In which object you have created list button ? So the selected records you want from which object ?
 
SFTerrSFTerr
Hi Manoj,
object: c2g__codaInvoice__c
VF page:
 
<apex:page standardController="c2g__codaInvoice__c"  extensions="SalesInvoicePrintReceipt"   applyBodyTag="{!p_applyHtmlTag}"   applyHtmlTag="{!p_applyHtmlTag}"   cache="{!p_cache}"   contentType="{!p_contentType}"   docType="{!p_docType}"   expires="{!p_expires}"   language="{!p_language}"   renderAs="{!renderAs}"   rendered="{!p_rendered}"   setup="{!p_setup}"   showChat="{!p_showChat}"   showHeader="{!p_showHeader}"   sidebar="{!p_sidebar}"   standardStylesheets="{!p_standardStylesheets}"   wizard="{!p_wizard}" >
<head>
<script src="/soap/ajax/31.0/connection.js"></script>
<script src="/soap/ajax/31.0/apex.js"></script>
<script type="text/javascript">
    jQuery.noConflict();
    beenFocused = true;
    
    if (typeof SkyEditor === "undefined") {
        SkyEditor = {};
    }
    SkyEditor.messages = {
        REQUIRED_FIELD_MISSING: "{!Label.RequiredFieldMissing}",
        UNDOCUMENTED: "{!Label.Undocumented}",
        DELETEERROR: "{!Label.DeleteError}",
        SAVESUCCESS: "{!Label.SaveSuccess}",
        CONFIRMMESSAGE: "{!Label.ConfirmMessage}",
        UPDATEMESSAGE: "{!Label.UpdateMessage}",
        CONDITIONSEARCHERROR: "{!Label.ConditionSearchError}",
        INVALIDSESSION: "{!Label.InvalidSession}",
        ERRORMESSAG: "{!Label.ErrorMessage}",
        NOTSELECTERROR: "{!Label.NotSelectError}",
        NOTROWSELECTERROR: "{!Label.NotRowSelectError}",
        DELETECONFIRM: "{!Label.DeleteConfirm}",
        BULKEDITDIALOGTITLE: "{!Label.customBulkEditButtonLabel}",
        REPORTOBJECTNOTFOUND: "{!Label.ReportObjectNotFound}",
        DATEFORMATERROE: "{!Label.DateFormatError}",
        NUMBERFORMATERROE: "{!Label.NumberFormatError}",
        NUMBERVALUEENPTY: "{!Label.NumberValueEmpty}",
        CANVASCHECK: "{!Label.CanvasCheck}",
        REWRITECHECK: "{!Label.RewriteCheck}",
        QUERY_PAGING_CONFIRMATION: "{!Label.QueryPagingConfirmation}",
        PAGE_NOT_SUPPORTED_ON_S1: "{!JSENCODE(Label.PageNotSupportedOnS1)}",
        PRICEBOOK_CHANGE:"{!JSENCODE(Label.pricebookChange)}"
    };
    SkyEditor.labels = {
        CANVASTITLE: "{!Label.CanvasTitle}",
        CheckAllText: "{!Label.CheckAllText}",
        UnCheckAllText: "{!Label.UnCheckAllText}",
        NoneSelectedText: "{!Label.NoneSelectedText}",
        SelectedText: "{!Label.SelectedText}",
        OptionLabelNon: "{!Label.None}",
        SelectButtonLabel: "{!label.SelectRecord}",
        SearchButtonLabel: "{!customSearchButtonLabel}",
        closeButton:"{!label.customBulkEditWindowCloseButtonLabel}",
        cancelButton:"{!customCancelButtonLabel}"
    };
        
    SkyEditor.SessionId = "{!$Api.Session_ID}";
    SkyEditor.CurrentPageName = "{!$CurrentPage.Name}";
    SkyEditor.UserId = "{!$User.Id}";
    SkyEditor.UserLanguage = "{!userLanguage}";
    SkyEditor.namespace = "SkyEditor2";
    SkyEditor.PageMode = "{!mode}";
    SkyEditor.RecordId = "{!record.Id}";
    SkyEditor.mainObject = "c2g__codaInvoice__c";
    SkyEditor.setProperty && SkyEditor.setProperty("labels.Picklist.none", "{!label.none}");
    SkyEditor.canvasSetting = {};
    SkyEditor.originCanvasSetting = {};
    SkyEditor.penImages = {
                            "2":"{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/images/pen2.gif')}",
                            "3":"{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/images/pen3.gif')}",
                            "4":"{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/images/pen4.gif')}"
                          };
    SkyEditor.canvasFlag = {};
    SkyEditor.isShowDetailPanel = {!sve_detailPageName != null};
    SkyEditor.isPageInit = {!isPageInit};
    
    SkyEditor.searchConditionFromTo="";
    SkyEditor.searchConditionItem="";
    SkyEditor.Mod.Sidebar.ModifiedPinMethod();
    sforce.connection.sessionId = "{!$Api.SESSION_ID}";
    SkyEditor.afterScriptLoaded();
</script>


<style>
{!HTMLENCODE(pdfStyleString)}
</style></head>
<apex:stylesheet value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/jquery-ui-1.8.19.custom.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/skyeditor2_tablesorter.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/jquery.multiselect.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/skyeditor2_styles.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/pure-grids-nr-min.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'json2.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/jquery-1.7.2.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/jquery-ui-1.8.19.custom.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/jquery.math.1.0.js')}" />
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/jquery.tablesorter.js')}" />
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/addons/pager/jquery.tablesorter.pager.js')}" />
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/tableSortPageingSetting.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/jquery.bgiframe.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/jquery.multiselect.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/skyeditor2_core.js')}" />
<apex:includeScript value="{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/js/jquery.layout.min.js')}" />
<script type="text/javascript">

</script>
<script type="text/javascript" import="true">

</script>

<apex:outputPanel id="messagesPanel">
<apex:pageMessages id="sveErrMsgs" rendered="{!errorMessages == ''}"/>
<apex:pageMessage summary="{!errorMessages}" severity="error" strength="2" escape="false" rendered="{!errorMessages != ''}"/>
<apex:pageMessage summary="{!infoMessages}" severity="info" strength="2" escape="false" rendered="{!infoMessages != ''}"/>
</apex:outputPanel>

<img src="/img/loading32.gif" id="SkyeditorLoagingImage" style="display:none;"/>

<table border="0" cellpadding="0" cellspacing="0" style="width:100%;" ><tr><td>
<apex:outputPanel rendered="{! NOT(hidePageBody)}" id="pagePanel" styleClass="base" layout="block">
<apex:outputPanel style="position:relative;" >
<apex:sectionHeader subtitle="{!record.Name}"   title="{!$ObjectType.c2g__codaInvoice__c.Label}"  >
</apex:sectionHeader></apex:outputPanel><apex:form id="sve_form1"   styleClass="sve_form1"   >
<apex:outputPanel id="Details_Wrapper" styleClass="">
<apex:pageBlock id="Details"   mode="detail"   title="Details"   >
<apex:pageBlockButtons location="both"   >
<apex:outputPanel id="Component14_Wrapper" layout="{!IF(p_isPdf==true,'block','')}" style="">
<apex:commandButton id="Component14"   value="Print Receipt"   style="width:66px;" >
</apex:commandButton>
</apex:outputPanel>
</apex:pageBlockButtons><apex:outputPanel id="Information_Wrapper"   styleClass="columns2"   >
<apex:pageBlockSection collapsible="true"   columns="2"   id="Information"   showHeader="true"   title="Information"  >
<apex:pageBlockSectionItem labelStyleClass="sve_pbSectionItem"   id="Component5"    onLabelclick="if(SkyEditor.isAndroid){SkyEditor.touchToolTip('{!$Component.Component5}');}">
<apex:outputLabel escape="true"   id="Component3"   rendered="{!$ObjectType.c2g__codaInvoice__c.fields.c2g__Account__c.accessible}"   style="width:100px;" value="{!$ObjectType.c2g__codaInvoice__c.fields.c2g__Account__c.label}" onclick="SkyEditor.touchToolTip('{!$Component.Component3}');"/>
<apex:outputPanel styleclass="fieldwrapper " style="width:300px;color:#000000;font-size:1.0em;font-weight:Normal;display:block;" >
<apex:outputField id="Component4"     value="{!record.c2g__Account__c}" />
</apex:outputPanel>
</apex:pageBlockSectionItem><apex:pageBlockSectionItem labelStyleClass="sve_pbSectionItem"   id="Component26"    onLabelclick="if(SkyEditor.isAndroid){SkyEditor.touchToolTip('{!$Component.Component26}');}">
<apex:outputLabel escape="true"   id="Component24"   rendered="{!$ObjectType.c2g__codaInvoice__c.fields.Sales_Invoice_Salesforce_ID__c.accessible}"   style="width:100px;" value="{!$ObjectType.c2g__codaInvoice__c.fields.Sales_Invoice_Salesforce_ID__c.label}" onclick="SkyEditor.touchToolTip('{!$Component.Component24}');"/>
<apex:outputPanel styleclass="fieldwrapper " style="color:#000000;font-size:1.0em;font-weight:Normal;" >
<apex:outputField id="Component25"     value="{!record.Sales_Invoice_Salesforce_ID__c}" />
</apex:outputPanel>
</apex:pageBlockSectionItem><apex:pageBlockSectionItem labelStyleClass="sve_pbSectionItem"   id="Component8"    onLabelclick="if(SkyEditor.isAndroid){SkyEditor.touchToolTip('{!$Component.Component8}');}">
<apex:outputLabel escape="true"   id="Component6"   rendered="{!$ObjectType.c2g__codaInvoice__c.fields.c2g__Opportunity__c.accessible}"   style="width:100px;" value="{!$ObjectType.c2g__codaInvoice__c.fields.c2g__Opportunity__c.label}" onclick="SkyEditor.touchToolTip('{!$Component.Component6}');"/>
<apex:outputPanel styleclass="fieldwrapper " style="width:300px;color:#000000;font-size:1.0em;font-weight:Normal;display:block;" >
<apex:outputField id="Component7"     value="{!record.c2g__Opportunity__c}" />
</apex:outputPanel>
</apex:pageBlockSectionItem><apex:outputPanel ></apex:outputPanel><apex:pageBlockSectionItem labelStyleClass="sve_pbSectionItem"   id="Component20"    onLabelclick="if(SkyEditor.isAndroid){SkyEditor.touchToolTip('{!$Component.Component20}');}">
<apex:outputLabel escape="true"   id="Component18"   rendered="{!$ObjectType.c2g__codaInvoice__c.fields.Name.accessible}"   style="width:100px;" value="{!$ObjectType.c2g__codaInvoice__c.fields.Name.label}" onclick="SkyEditor.touchToolTip('{!$Component.Component18}');"/>
<apex:outputPanel styleclass="fieldwrapper " style="width:300px;color:#000000;font-size:1.0em;font-weight:Normal;display:block;" >
<apex:outputField id="Component19"     value="{!record.Name}" />
</apex:outputPanel>
</apex:pageBlockSectionItem><apex:outputPanel ></apex:outputPanel><apex:pageBlockSectionItem labelStyleClass="sve_pbSectionItem"   id="Component23"    onLabelclick="if(SkyEditor.isAndroid){SkyEditor.touchToolTip('{!$Component.Component23}');}">
<apex:outputLabel escape="true"   id="Component21"   rendered="{!$ObjectType.c2g__codaInvoice__c.fields.c2g__InvoiceDate__c.accessible}"   style="width:100px;" value="{!$ObjectType.c2g__codaInvoice__c.fields.c2g__InvoiceDate__c.label}" onclick="SkyEditor.touchToolTip('{!$Component.Component21}');"/>
<apex:outputPanel styleclass="fieldwrapper " style="width:300px;color:#000000;font-size:1.0em;font-weight:Normal;display:block;" >
<apex:outputField id="Component22"     value="{!record.c2g__InvoiceDate__c}" />
</apex:outputPanel>
</apex:pageBlockSectionItem><apex:outputPanel ></apex:outputPanel></apex:pageBlockSection>
<script type="text/javascript">
    decorateSectionHeader('Information', {"isFirstSection":true,"isMarginRemove":false});
    if(SkyEditor.isSalesforce1()){
        var imgUrl = "{!URLFOR($Resource.SkyEditor2__skyEditor2, 'skyeditor2/3_6/css/images/helpimg.png')}"
        SkyEditor.sveHelpImageForSalesforce1(imgUrl, jQuery('.sve_pbSectionItem .helpButton img.helpOrb'));
    }
</script></apex:outputPanel></apex:pageBlock>
</apex:outputPanel></apex:form><apex:outputPanel style="position:relative;" >
</apex:outputPanel><script type="text/javascript">
function aggregateCalc_all(triggerId) {
}
</script>
</apex:outputPanel>
</td></tr></table>
<div id="CustomLookupForSFoneDialog" style="display:none;" >
    <apex:pageBlock >
        <div id="CustomLookUpForSFoneConditons">
        </div> 
        <div id="CustomLookUpForSFoneTextConditons" style="clear:left;">
        </div><br style="clear:left;" />
    </apex:pageBlock>
    <apex:pageBlock >
        <apex:pageBlockButtons location="top" styleClass="CustomLookUpForSFoneButtons">
        </apex:pageBlockButtons>
        <div style="height:480px; overflow-y:scroll;" >
            <table class="list" id="CustomLookUpForSFoneListTable" cellspacing="0" cellpadding="0" border="0" >
                <thead class="CustomLookUpForSFoneListHeader">
                </thead>
                <tbody class="CustomLookUpForSFoneListBody"> 
                </tbody>
            </table>
        </div>
    </apex:pageBlock>
</div>
</apex:page>

 
ManojjenaManojjena
Hi ,
I got that the object is c2g__codaInvoice__c . So you have created a list button is this object and overridden by this page .You want the selected records from related list right ?

 
SFTerrSFTerr
Hi, I want users to select one record from that object list view, click on the "Print Receipt (test)" button and be able to view details of selected record. As attached.User-added image
ManojjenaManojjena
Hi ,

Please check below code and try to implement with your code .Do a POC with this code then implement .
<apex:page standardController="c2g__codaInvoice__c"  extensions="SalesInvoicePrintReceipt"  recordSetVar="c2g__codaInvoice__c" applyBodyTag="{!p_applyHtmlTag}"   applyHtmlTag="{!p_applyHtmlTag}"   cache="{!p_cache}"   contentType="{!p_contentType}"   docType="{!p_docType}"   expires="{!p_expires}"   language="{!p_language}"   renderAs="{!renderAs}"   rendered="{!p_rendered}"   setup="{!p_setup}"   showChat="{!p_showChat}"   showHeader="{!p_showHeader}"   sidebar="{!p_sidebar}"   standardStylesheets="{!p_standardStylesheets}"   wizard="{!p_wizard}" >
</apex:page>

public class SalesInvoicePrintReceipt{
    public List<c2g__codaInvoice__c> cdlist;
    public set<id> slectedrecordid;
    ApexPages.StandardSetController setCon;
    public SalesInvoicePrintReceipt(ApexPages.StandardSetController controller){
	    cdlist=new List<c2g__codaInvoice__c> ();
		setCon=controller;
		 for(c2g__codaInvoice__c con:(c2g__codaInvoice__c[])setCon.getSelected()){
            slectedrecordid.add(con.id);
        }
		 cdlist=[SELECT Id,Fileds FROM c2g__codaInvoice__c WHERE Id IN : slectedrecordid];
System.debug('****************'+cdlist);
}

Better you can check in bebug you will get all fields which you have added in your query .Please change teh query by adding your required  fields .
SFTerrSFTerr
Hi, so I’ve added below instead of apex class:
public class SalesInvoicePrintReceipt{
        public List<c2g__codaInvoice__c> cdlist;
        public set<id> slectedrecordid;
        ApexPages.StandardSetController setCon;
        public SalesInvoicePrintReceipt(ApexPages.StandardSetController controller){
            cdlist=new List<c2g__codaInvoice__c> ();
            setCon=controller;
             for(c2g__codaInvoice__c con:(c2g__codaInvoice__c[])setCon.getSelected()){
                slectedrecordid.add(con.id);
            }
             cdlist=[SELECT Id,c2g__Account__c, c2g__Opportunity__c, Name, c2g__InvoiceDate__c FROM c2g__codaInvoice__c WHERE Id IN : slectedrecordid];
    System.debug('c2g__Account__c, c2g__Opportunity__c, Name, c2g__InvoiceDate__c'+cdlist);
    }
}
and I tried to add below as the first line of the VF page
<apex:page standardController="c2g__codaInvoice__c" extensions="SalesInvoicePrintReceipt" recordSetVar="c2g__codaInvoice__c" applyBodyTag="{!p_applyHtmlTag}"  applyHtmlTag="{!p_applyHtmlTag}"  cache="{!p_cache}"  contentType="{!p_contentType}"  docType="{!p_docType}"  expires="{!p_expires}"  language="{!p_language}"  renderAs="{!renderAs}"  rendered="{!p_rendered}"  setup="{!p_setup}"  showChat="{!p_showChat}"  showHeader="{!p_showHeader}"  sidebar="{!p_sidebar}"  standardStylesheets="{!p_standardStylesheets}"  wizard="{!p_wizard}" >
(instead of the previous one), but I'm getting an error:
Error: Unknown property 'c2g__codaInvoice__cStandardController.p_showHeader'
when I remove it it gives me
Error: Unknown property 'c2g__codaInvoice__cStandardController.p_applyHtmlTag'
and so on

am I doing something wrong?