3

I am trying to pull list of contacts with no accountId showing if the contact owner is active or not.

Page:

    <apex:pageblockTable value="{!EmptyAccount_contact}" var="a">
        <apex:column value="{!a.id}"/>         
        <apex:column value="{!a.ownerId}"/>            
        <apex:column >            
            <apex:facet name="header">Status</apex:facet>
            {!isActive}
        </apex:column>
        <apex:column value="{!a.email}"/>
    </apex:pageblockTable>

My question is how should i define "isActive" method so the status column can show true or false if contact owner is active or not

Controller:

public list<contact> getEmptyAccount_contact(){
    list<contact> con = new list<contact>([SELECT id, name, email, accountId, phone,OwnerId  from contact where accountId = null LIMIT 1000]);
    return con;
}

Thanks.

1 Answer 1

4

You need to query the contact owner isActive field also in contact query.

public list<contact> getEmptyAccount_contact(){
    list<contact> con = new list<contact>([SELECT id, name, email, accountId, phone,OwnerId,owner.isActive  from contact where accountId = null LIMIT 1000]);
    return con;
}

Then in the page you can display as below,

<apex:pageblockTable value="{!EmptyAccount_contact}" var="a">
        <apex:column value="{!a.id}"/>         
        <apex:column value="{!a.ownerId}"/>            
        <apex:column >            
            <apex:facet name="header">Status</apex:facet>
            {!a.Owner.isActive}
        </apex:column>
        <apex:column value="{!a.email}"/>
    </apex:pageblockTable>

If you want to show it as checkbox replace {!a.Owner.isActive} with <apex:outputField value="{!a.Owner.isActive}"/>

2
  • Your solution worked perfectly. But I have a question. Can i change the ext "true/ false" to "Active/ not active" under status column ?
    – sf_user
    Commented Jun 8, 2015 at 18:49
  • 1
    Sure you can use IF condition in visualforce page. Replace the field with {!IF(a.Owner.isActive,"Active","Not Active")}
    – Victor
    Commented Jun 8, 2015 at 18:51

You must log in to answer this question.

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