1

You have an object. It has a related list. If your related list has more than 5 elements you have "Go to list (55+) »" link under it. If you hit that link, you're redirected to a page with a table of those items.

The URL of this page contains two params. One of it is id of 'master' object. Now, when you override List page, you're redirected to your page, BUT there is no id param anymore. And list contains wrong items (actually, just all records). What I'm doing wrong?

<apex:page 
  standardController="Custom_Object__c"
  recordSetVar="coList"
  standardStylesheets="true"
  tabStyle="Custom_Object__c"
>

  <apex:pageBlock>
    <apex:pageBlockTable value="{!coList}" var="coItem" >
      <apex:column value="{!coItem.Name}"/>
      <apex:column value="{!coItem.Field01__c}"/>
      <apex:column value="{!coItem.Field02__c}"/>
      <apex:column value="{!coItem.Total_Price__c}"/>
   </apex:pageBlockTable>
  </apex:pageBlock>

</apex:page>

Then I said, OK.

<apex:page 
  standardController="Custom_Object__c" extensions="CO_Extension"
  recordSetVar="coList"
  standardStylesheets="true"
  tabStyle="Custom_Object__c"
>

  <apex:pageBlock>
    <apex:pageBlockTable value="{!coList}" var="coItem" >
      <apex:column value="{!coItem.Name}"/>
      <apex:column value="{!coItem.Purchase_Order_Number__c}"/>
      <apex:column value="{!coItem.Accubid_Number__c}"/>
      <apex:column value="{!coItem.Total_Price__c}"/>
   </apex:pageBlockTable>
  </apex:pageBlock>

</apex:page>

Extension:

public with sharing class CO_Extension {

  public Decimal totalPrice { get; private set; }

  Id caseId { get; set; }

  public CO_Extension() {
    totalPrice = 0;
  }

  public CO_Extension(ApexPages.StandardSetController setController) {
    this();
    caseId = ApexPages.currentPage().getParameters().get('id');
System.debug(LoggingLevel.DEBUG,
  '\n\n --- CO_Extension --- '
  +'\n - ApexPages.currentPage().getParameters(): ' + ApexPages.currentPage().getParameters()
  +'\n - setController: ' + setController
  +'\n - setController.getResultSize(): ' + setController.getResultSize()
  +'\n - setController.getRecords(): ' + setController.getRecords()
  +'\n'
);

}

The same result, it shows ALL records. There is no ID in the page parameters (of course, there is no id param in URL).

What am I doing wrong?

Oh, yes, if I remove overriding of List view, it displays right items.

  • Just curious, are you still an active user? I just added a way you can do this without any Javascript. – Adrian Larson Jun 14 '16 at 15:26
  • @AdrianLarson, I'm not really 'active' nowdays ;-) I don't remember where and why I had this problem. I don't have time to check if this is working or not. Probably, this question may be closed. For now. – Andrii Muzychuk Jun 15 '16 at 8:31
0

You can get the object as

Custom_Object__c obj = (Custom_Object__c)stdController.getRecord();

ID of the object obj is what you are looking for.

Alternate approach as suggested by @Unidha also works which is

ID caseId = stdController.getId();
  • 1
    stdController.getId() also will return the Id right? – unidha Oct 27 '14 at 5:51
  • @unidha Yes, that can be used as well. – Ganesh Bhosle Oct 27 '14 at 5:53
  • In both variants there is no stdController. There is stdSetController of type ApexPages.StandardSetController. It contains ALL object, but not those which are related to 'master' object. – Andrii Muzychuk Oct 27 '14 at 12:44
0

I came up with frustrating but working solution. I don't like it (I don't like embedding Javascript into VF page).

<apex:page 
  standardController="Custom_Object__c" extensions="CO_Extension"
  recordSetVar="coList"
  standardStylesheets="true"
  tabStyle="Custom_Object__c"
>

  <script>

  var redirectFromURL = document.referrer + "/";

  var caseId = getURLParameter('id');
  //alert(caseId);
  if (caseId == null || (caseId.length != 15 && caseId.length != 18)) {
    //debugger;
    if (redirectFromURL.substring(redirectFromURL.length - 1) == "/") {
      redirectFromURL = redirectFromURL.substring(0, redirectFromURL.length - 1);
    }
    var lastIndexOf = redirectFromURL.lastIndexOf("/");
    caseId = redirectFromURL.substring(lastIndexOf + 1);
  }
  if (caseId != null && caseId.length == 15 || caseId.length == 18) { 
    window.location.assign("/apex/This_Visualforce_Page?rlid=00NJ0000001YUK8&id="+caseId+"&save_new=1&sfdc.override=1");
  }

  function getURLParameter(name) {
    //alert(document.referrer);
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(redirectFromURL)||[,""])[1].replace(/\+/g, '%20'))||null
  }

  </script>

  <apex:pageBlock>
    <apex:pageBlockTable value="{!coList}" var="coItem" summary="Total: 3000.44">
      <apex:column> <apex:facet name="header">{!$ObjectType.Custom_Object__c.Fields.Name.Label}</apex:facet> <a href="/{!coItem.Id}">{!coItem.Name}</a> </apex:column>
      <apex:column value="{!coItem.Field1__c}"/>
      <apex:column value="{!coItem.Field2__c}"/>
      <apex:column value="{!coItem.Field3__c}"/>
   </apex:pageBlockTable>
  </apex:pageBlock>
  <apex:outputPanel style="width: 100%; text-align:right; align:right; position: absolute; right: 10px;" >
    <apex:outputText style="text-align:right; right: 40px; " value="Total Price: " />
    <apex:outputText style="text-align:right;  font-size: medium " value="{!totalPrice}" />
  </apex:outputPanel>
  <br/><br/>

</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.