1

I am trying to generate a basic apex OutputLink however the record Id is being displayed in the Visualforce Page Component instead of the record name.

How can I correctly format the url to display the record name (with url behind it)?

Any help is appreciated!

VF Page Component:

<apex:pageBlock >
    <apex:pageBlockTable value="{! coverageTeam }" var="member">
        <apex:column >
            <apex:facet name="header">Role</apex:facet>
            {! member.role }
        </apex:column>
        <apex:column >
            <apex:facet name="header">Name</apex:facet>
                <apex:outputLink value = "/{!member.name}"> 
                     {!member.name}
                </apex:outputLink>          
        </apex:column>
    </apex:pageBlockTable>
</apex:pageBlock>

======================================================================

Apex Controller:

public with sharing class SL_ctrl_AccountCoverageTeam_comp {

    private final ApexPages.StandardController controller;
    public String accountId {get;set;}

    public SL_ctrl_AccountCoverageTeam_comp() { 
        //accountId = ApexPages.currentPage().getParameters().get('id');
    }

    public List<CoverageTeamMember> getCoverageTeam() {
        if(this.controller != null)
            return this.getCoverageTeam( getAccount( this.controller.getId() ) );
        else
            return this.getCoverageTeam( getAccount( accountId ) );
    }

    private Account getAccount( ID account ) {
        return [ SELECT Producer__r.Name, Servicer_1__c, Servicer_2__c FROM Account WHERE Id = :account ];
    }

    private List<CoverageTeamMember> getCoverageTeam( Account account ) {
        List<CoverageTeamMember> result = this.getStaticCoverageTeam( account );

        for ( AggregateResult policy : [ 
            SELECT Servicer_Department_Name__c role, Servicer__r.Id name, Active__c a 
            FROM Policy__c 
            WHERE Account__c = :account.Id AND 
                Servicer_Department_Name__c != null AND
                Servicer__c != null AND
                Active__c = True
            GROUP BY Servicer_Department_Name__c, Servicer__r.Id, Active__c
        ] ) {
            result.add( new CoverageTeamMember( policy ) );
        }

        return result;
    }

    private List<CoverageTeamMember> getStaticCoverageTeam( Account account ) {
        List<CoverageTeamMember> result = new List<CoverageTeamMember>();
        result.add( new CoverageTeamMember( 'Producer', account.Producer__r.Id ) );
        result.add( new CoverageTeamMember( 'Client Owner', account.Servicer_1__c ) );
    }

    public class CoverageTeamMember {
        public final String role { get; set; }
        public final String name { get; set; }

        public CoverageTeamMember( AggregateResult policy ) {
            this( String.valueOf( policy.get( 'role' ) ), String.valueOf( policy.get( 'name' ) ) );
        }

        public CoverageTeamMember( String role, String name) {
            this.role = role;
            this.name = name;

        }
    }
}
1
  • Yes - I would need to display the name and not the record ID - they're not one and the same in this case.
    – SFDC-ThEq
    Commented Mar 3, 2016 at 20:53

2 Answers 2

2

You have variable 'name' assigned an Id. So you should create one more variable in your CoverageTeamMember wrapper class and assign the name from the aggregate query.

public class CoverageTeamMember {
    public final String role { get; set; }
    public final String name { get; set; }
    public final String actualname { get; set; }

    public CoverageTeamMember( AggregateResult policy ) {
        this( String.valueOf( policy.get( 'role' ) ), String.valueOf( policy.get( 'name' ) ), String.valueOf( policy.get( 'actualname' ) ) );
    }

    public CoverageTeamMember( String role, String name,String actualname) {
        this.role = role;
        this.name = name;
        this.actualname = actualname;
    }
}

Then the following query

SELECT Servicer_Department_Name__c role, Servicer__r.Id name, Active__c a FROM Policy__c

should be changed to

SELECT Servicer_Department_Name__c role, Servicer__r.Id name, Servicer__r.Name actualname, Active__c a FROM Policy__c

EDIT:

As per comments, the error is because of the getStaticCoverageTeam method which calls the two parameter constructor of wrapper class.

private List<CoverageTeamMember> getStaticCoverageTeam( Account account ) {
    List<CoverageTeamMember> result = new List<CoverageTeamMember>();
    result.add( new CoverageTeamMember( 'Producer', account.Producer__r.Id, 'Pass third parameter here' ) );
    result.add( new CoverageTeamMember( 'Client Owner', account.Servicer_1__c ), 'Pass third parameter here' );
}

Pass whatever name you want to be populated as third parameter.

Hope this helps.

7
  • Thanks Vigneshwaran G! I tried that approach but receive error "Constructor not defined: [SL_ctrl_AccountCoverageTeam_comp.CoverageTeamMember].<Constructor>(String,Id). Appreciate your help!
    – SFDC-ThEq
    Commented Mar 3, 2016 at 20:50
  • You should change the two parameter constructor to three parameter constructor as i did in my example above. Commented Mar 3, 2016 at 20:53
  • Yes! I have 3 parameters.
    – SFDC-ThEq
    Commented Mar 3, 2016 at 20:57
  • public class CoverageTeamMember { public final String role { get; set; } public final String name { get; set; } public final String actualname { get; set; } public CoverageTeamMember( AggregateResult policy ) { this( String.valueOf( policy.get( 'role' ) ), String.valueOf( policy.get( 'name' ) ), String.valueOf( policy.get( 'actualname' ) ) ); } public CoverageTeamMember( String role, String name,String actualname) { this.role = role; this.name = name; this.actualname = actualname; } }
    – SFDC-ThEq
    Commented Mar 3, 2016 at 20:58
  • Please take a look at the updated answer. Commented Mar 3, 2016 at 21:04
1

If you simply use an apex:outputField instead, it should display the record's name as a clickable link

1
  • apex:outputField can be used with Sobject records only. OP using wrapperclass here. Commented Mar 3, 2016 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .