2

I have a requirement to show page message for a particular selected template. The template selection done here. But render is always returning true in this case. Can someone help me here?

<apex:selectList id="chooseTempalte" label="Choose Template" title="Select your Template"        value="{!selectedTemplateId}" size="1" onChange="rerenderEmailFields(this.value)">
   <apex:selectOptions value="{!TemplateOptions}"/>
</apex:selectList>

<apex:outputLabel style="color:red;"  rendered="{!IF(selectedTemplateId='Update Status - Send to ABSM', false, true)}" >  
  Please note this selected option  will set the status value to Under Review <br/><br/>
</apex:outputLabel>

Please find the apex controller snippet here.

public List<SelectOption> getTemplateOptions() {
        options = new List<SelectOption>();
        for (EmailTemplate t : etMap.values()) {
            options.add(new SelectOption(t.Id,t.Name));
            if((selectedTemplateId == '' || selectedTemplateId == null) && t.Name == 'Update Status - Send to ABSM')
            {
                selectedTemplateId = t.Id;
                ApplyTemplate();
            }
        }

    return options;
}    
  • Are you saying that {!IF(selectedTemplateId='Update Status - Send to ABSM', false, true)} is always true? – BarCotter Dec 10 '14 at 10:44
  • 1
    are you sure the templateId is a label and not a string? Could you include the Apex code where you're setting up the TemplateOptions? – Guy Clairbois Dec 10 '14 at 10:44
  • possible duplicate of Render based on TemplateId – BarCotter Dec 10 '14 at 10:54
  • Hi Barcotter! yes the selectedtemplateid is a string which contains salesforce id of email template. I need to typecast that to ID and make like ID.Name=='Update...'. – Testing_SFDC Dec 10 '14 at 12:46
  • 1
    This had several flags saying it was a duplicate of your last question, though to my mind you showed that you had done some more work since and the question had changed somewhat, so I closed the other one. In future your best bet would be to edit the first question (assuming it doesn't have several answers). – Matt Lacey Dec 10 '14 at 23:20
1

You're assigning a record ID to selectedTemplateId with this:

selectedTemplateId = t.Id;

and then comparing it with a string in the page, which is why the comparison evaluates as false and then your IF() function returns true.

You haven't listed the code that populates etMap but as long as you're initialising it with a query that includes the Name field (or if it's coming from a trigger), then you should be able to do something like the following. I'm using a new variable (selectedTemplate) as I'm guessing the other is used as a page parameter.

public EmailTemplate selectedTemplate {get; set;}

public List<SelectOption> getTemplateOptions() {
    options = new List<SelectOption>();
    for (EmailTemplate t : etMap.values()) {
        options.add(new SelectOption(t.Id,t.Name));
        if((selectedTemplateId == '' || selectedTemplateId == null) && t.Name == 'Update Status - Send to ABSM')
        {
            selectedTemplateId = t.Id;
            selectedTempalte = t;
            ApplyTemplate();
        }
    }
    return options;
}    

Then in the page you can test against the name field as you want:

<apex:outputLabel style="color:red;"  rendered="{!IF(selectedTemplate.Name = 'Update Status - Send to ABSM', false, true)}" >  
  Please note this selected option  will set the status value to Under Review <br/><br/>
</apex:outputLabel>

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.