0

I have a page that creates a CSV of account and related data, i am trying to add a block that shows the users related to that account via a contact.

I have followed a few tutorials on how to make a custom list controller class however every iteration i have tried gives me a unknown constructor error.

Where is the issue?

Page

<apex:page standardController="Account" contentType="application/vnd.ms-excel#SalesForceExport.xls" cache="true"  extensions="AccountRegisteredPortalUsers">

    <apex:pageBlock title="Agency Planning" rendered="{!$user.id = account.CSM_owner__r.id}">
        <apex:pageBlockTable value="{!account.Cases}" var="item"> 
            <apex:column value="{!item.Subject}"/> 
            <apex:column value="{!item.Status}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>    

    <apex:pageBlock title="Entitlements" rendered="{!$user.id = account.CSM_owner__r.id}">
        <apex:pageBlockTable value="{!account.Entitlements}" var="Ent"> 
            <apex:column value="{!Ent.PlanType__C}"/> 
        </apex:pageBlockTable>
    </apex:pageBlock>    

    <apex:pageBlock title="RegisteredUsers" rendered="{!$user.id = account.CSM_owner__r.id}">
        <apex:pageBlockTable value="{!Usercont}" var="Ent"> 
            <apex:column value="{!Usercont.userid}"/> 
        </apex:pageBlockTable>
    </apex:pageBlock>   

</apex:page>

Controller

public class AccountRegisteredPortalUsers {

    public ApexPages.StandardSetController Usercont {
        get{
        if(Usercont == null) {
            Usercont = new ApexPages.StandardSetController(Database.getQueryLocator(
            [SELECT 
             id,
             Contactid
            FROM user Where contact.accountid = :ApexPages.currentPage().getParameters().get('id')]));
    }
    return Usercont;
    }
    set;
    }
    public AccountRegisteredPortalUsers(ApexPages.StandardSetController controller) {
    }

//Initalize orderSetCont and return a list of records
    public List<User> getuserDets() {
        return (List<User>) Usercont.getRecords();
    }
}
4

You need a recordSetVar="accounts" attribute on your <apex:page> tag. Otherwise, the Visualforce system believes you to be using an ApexPages.StandardController rather than an ApexPages.StandardSetController.

As a result, you get a constructor-related error because Visualforce is looking for

public AccountRegisteredPortalUsers(ApexPages.StandardController controller)

and you have

public AccountRegisteredPortalUsers(ApexPages.StandardSetController controller)
| improve this answer | |
  • Worked perfectly, however now the standard records for <apex:pageBlockTable value="{!account.Entitlements}" var="Ent"> and cases dont show any values, i did think perhaps it was because it didn't recognise the 'rendered' account check but removing that doesn't help. Is there something i should look at to allow the standard and Ext records to display side by side? Thanks – user37980 Aug 13 '18 at 22:02
  • 1
    You don't appear to have an account property accessible anywhere. Is this code complete? – David Reed Aug 13 '18 at 22:10
  • It is, im sure there is something im missing. Originally i returned the two child lists using value="{!Account.Cases}". Has adding the extension and 'StandardSetController' Removed the relationship for these fields? If so what is the best way of getting access to those sObjects/Fields again? – user37980 Aug 14 '18 at 10:04
  • A standard set controller controls a collection of objects, in this case Accounts. It doesn't have a property for a single Account. You'd need to iterate over its contents using a component like <apex:repeat>. I don't have enough clarity on what you're trying to do to make a more concrete recommendation, but if you aren't working with a set of objects, a set controller is probably not what you want. – David Reed Aug 14 '18 at 13:34
  • 1
    That does not sound like a use case for a set controller - you probably just want the standard controller. – David Reed Aug 14 '18 at 14:05

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.