1

I am using a visualforce email template from Apex Batch class.That visual forc template is using a component for email body generation. Now, I am using custom setting(type list) to get dynamic email body based on country. But I am unable to access the custom settings field value(line1__c, line2__c etc from below code) from either constructor or getter setter.

Please note, when I am using harcoded text instead of custom settings field, the email works absolutely fine.

Below is the code.

Email Template:

<messaging:emailTemplate subject="Pending Letter" recipientType="Contact" 
 relatedToType="Return__c">
  <messaging:htmlEmailBody >
    <c:Pending_Letter caseId="{!relatedTo.Case__r.Id}" contactId={!relatedTo.Case__r.Contact.Id}"/>
  </messaging:htmlEmailBody>
</messaging:emailTemplate>

Vf Component:

<apex:component access="global" controller="Reminder_Letter">
<apex:attribute name="contactId" type="Id" description="Id of the Contact" assignTo="{!contact}"/>
<apex:attribute name="caseId" type="Id" description="Id of the Case" assignTo="{!cId}"/>  
 {!customSettings.Line1__c} <br/>
 {!customSettings.Line2__c}
 <apex:dataTable value="{!returnList}" var="pr" id="dtCaseInfo"
                 rowClasses="odd,even" styleClass="tableClass">
    <apex:column >
        <apex:facet name="header"> Serial Number  </apex:facet>
        <apex:outputText value="{!pr.Issue__r.SerialNumber__c}"/>
    </apex:column>
    </apex:dataTable>  
   {!customSettings.Line3__c}
   <br/>
   <br/>
    {!customSettings.Line4__c}
 </apex:component>

Controller:

public class ADC_Ctrl_Reminder_Letter { 
public Id cId {get;set;}
public Id contact {get;set;}
//customSettings
Reminder_Letter__c customSettings{get;set;}


List<Product_Return__c> ReturnList;

public ADC_Ctrl_Reminder_Letter(){
    customSettings = Reminder_Letter__c.getInstance('USA');
}

//List to be used in VF
Public List<Product_Return__c> getReturnList(){
   if(cId != null) {
       productReturnList = new List<Product_Return__c>([Select  
                                                        Id, Name,Return_Status__c, Case__c, Issue__c
                                                        FROM 
                                                        Return__c 
                                                        WHERE Return_Status__c  IN ('Pending')
                                                        AND Case__c =: cId] );
       return ReturnList;
   }
   return null;
  } 
}
1
  • @TusharSharma- Posted it here.Please check Commented Apr 23, 2017 at 3:38

1 Answer 1

1

You have to declare customSettings as public access modifier to use it in visualforce page.

Wrong code (without access modifier, that is default access in controller).

Reminder_Letter__c customSettings{get;set;}

Correct Code

public Reminder_Letter__c customSettings{get;set;}

List<Reminder_Letter__c> reminderLetterSettings = Reminder_Letter__c.getall().values();

//check for which attribute you are comparing with 'USA'
if (reminderLetterSettings[0].<attrbiute api> == 'USA') {
  customSettings = reminderLetterSettings[0];
}

For more information, refer Accessing Custom Settings

4
  • Corrected. Its a typo while posting here...But still my problem persists. Commented Apr 23, 2017 at 3:58
  • same result with get values and getInstance.. :( . this is a public list type custom settings Commented Apr 23, 2017 at 4:26
  • 1
    can you use public access modifier, public Reminder_Letter__c customSettings{get;set;} Commented Apr 23, 2017 at 4:28
  • Ohh yes..you are correct...thank you.... Not sure why I make the same mistake again n again.. Commented Apr 23, 2017 at 4:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.