7

I need to display text based on record type & has teammember.But it displays both messages regardless of record type.Below is the part of my visualforce page.

<apex:outputLabel style="color:red;" 
                  rendered="{!IF(HasTeamMember && ENT_ED_LIHTC__c.recordtype.name =='Standard Deal', false, true)}" >
    Note: At least one Team Member with Role as Originator is required.<br/><br/>
</apex:outputLabel>

<apex:outputLabel style="color:red;" 
                  rendered="{!IF(HasTeamMember && ENT_ED_LIHTC__c.recordtype.name!='Standard Deal', false, true)}" >
    Note: At least one Team Member is required.<br/><br/>
</apex:outputLabel>

public boolean HasTeamMember
{
    get
    {
      ENT_ED_LIHTC__c deal = (ENT_ED_LIHTC__c)ctrl.getRecord();
      List<ENT_Enterprise_Team__c> tmForInsert = new List<ENT_Enterprise_Team__c>();
      list<RecordType> rtype =[Select id,recordtype.name From recordtype where id =:deal.recordtypeid];

        if(TeamMembers.size() > 0)
        {
            for(ENT_Enterprise_Team__c tm : TeamMembers)
            {
                if(tm.User__c != null && tm.Role__c != null && tm.Role__c != ''&& tm.Role__c == 'Originator' && rtype[0].name=='Standard Deal')
                {
                    return true;
                }

                if(tm.User__c != null && tm.Role__c != null && tm.Role__c != '' && rtype[0].name!='Standard Deal')
                {
                    return true;
                }
            }

            return false;
        }
        else
            return false;
    }
}
5
  • Can you show us the code snippet where your variable HasTeamMember is calculated? And what do you mean with Vf page is not displaying.? You mean output label? Oct 11, 2013 at 15:14
  • @mast0r updated the code
    – sfdc
    Oct 11, 2013 at 15:20
  • Just as a side note, you really shouldnt mix your logic like this. You have some logic being performed in the controller, and some on the VF page. You really should perform all of your logic in the controller and reference that controller property in your VF rendered attribute Oct 11, 2013 at 15:28
  • yes outputlabel was not displaying when I pasted the code.How did you do that ?
    – sfdc
    Oct 11, 2013 at 15:29
  • You should use DeveloperName instead of Name when querying the record types. Oct 11, 2013 at 15:41

2 Answers 2

6

I've been able to make things like this by simply doing this:

render="{!HasTeamMeber && ENT_ED_LIHTC__c.recordtype.name =='Standard Deal'}"

At least it seems to work fine with a page I was working on.

Another way would be to have a Boolean method in your controller that returns true or false and put the logic there.

5

Generally your code is almost clear. If you can not see labels on the page that means that your formula condition just returns false. Try to figure out why it is happening. Make some debug outputs in HasTeamMember. Maybe TeamMembers size is 0? The simplest thing what you can do is to output these two variables on the visualforce page to check it content:

HasTeamMember: {!HasTeamMember} <br/>
Recordtype: {!ENT_ED_LIHTC__c.recordtype.developername}

Then you will see what that variables really are.

Some tips to improve your page and controller:

  • You dont realy need to use List when querying record type name. You can use this construct: String rtype =[Select DeveloperName From recordtype where id =:deal.recordtypeid].DeveloperName;
  • Use DeveloperName instead of Name when querying the record types. DeveloperName is a unique name of the object in the API and Name is just a label
  • As @Dunc44 said pack all of your logic in to the controller. Why don't use ENT_ED_LIHTC__c.recordtype.name =='XXX' construct within the HasTeamMember method? It's more convenient
  • Check variables with System.debug outputs or directly on the page to see what they are really doing

I hope it will help you, good luck.

You must log in to answer this question.

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