1

I have a visualforce email template. I use a visualforce component in it and an apex controller to display some data in the email. Everything is fine till here. Now, I want to render some part of the email content based on User.Interests__c (a custom field in my user object).

So, I used rendered condition in an outputPanel and checking the Interests condition. Now, if the rendered is TRUE, email is sent perfectly (with the image rendered correctly). When the rendered condition is FALSE, email is NOT SENT.

Ideally, when the rendered condition is FALSE, email should be sent without the image in the outputpanel. What is wrong with this?

Please let me know. Here's the code:

VF template

    <tr>    
      <apex:outputPanel rendered="{!checkUserInterest}">       
          <td align="left"><img src="http://resources.dood.com/logo.png"/></td> 
      </apex:outputPanel>      
    </tr>

</table>

//Apex class code

public boolean isIA;
public boolean getcheckUserInterest() {
    if(User.User_Interests__c != null) {
        isIA = user.User_Interests__c.contains('Host')?true:false;
    }else {
        isIA = false;
    }
    return isIA;
}

PS: I had to use a controller and component for all this because Interests__c is a multi select picklist field. I cannot use CONTAINS(User.Interests__c) etc directly in output panel rendered condition. Thats limitation from Salesforce.

2
  • There is an unclosed td tag in what you posted, but I don;t see a cause of the problem.
    – Keith C
    Aug 6, 2014 at 9:01
  • Oh yes, my mistake. But that doesn't effect. Not working still
    – sfdcFanBoy
    Aug 6, 2014 at 9:31

3 Answers 3

0

Try this in your class:

public boolean isIA;
public boolean getcheckUserInterest() {
    if(User.User_Interests__c != null) {

       if(user.User_Interests__c.contains('Host') == true){
           isIA = true;
       }else {
           isIA = false;
       {
    }
    return isIA;
}
0
0

Try this

public boolean getcheckUserInterest() {
  return User.User_Interests__c != null
       ? user.User_Interests__c.contains('Host')
       : false;
}

When user.user_interest__c was null, you were returning uninitialized boolean variable isIA.

0

Thanks for the replies. I have resolved it now. It was nothing related to coding. My email address in the sandbox wasn't set correctly (It was still something like username#example.com). After I corrected it, it was working. Still wondering how the earlier emails were sent to me.

sorry, but thanks guys!

You must log in to answer this question.

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