You need to sign in to do that
Don't have an account?
James Allen 4
Passing multiple parameters to the component to be used in a where clause in the controller.
I am working on a VisualForce email template with a component and controller. I have it pulling a list of records from a custom object based on the Id of the related template record. However I need to add another parameter to the where clause based on another value from the record. I think I have it coded correctly but my query is not returning the expected results.
Is there a way to see a debug log of the controller when an email is sent?
Can you see any reason using the :cohortType variable in my SOQL where clause would not evaluate correctly to the value passed in from the template?
Section from Template
<b>Study Island PLC Cohort Series Schedule and Registration Links:</b>
<table border="1" width="600" >
<tr><th>Cohort Description</th><th>Select Cohort</th></tr>
<c:CohortRegisterComponent Cohort_Type="{!RelatedTo.Program__c}" Task_Id="{!RelatedTo.Id}" />
</table>
Compponent
<apex:component controller="CohortRegisterController" access="global">
<apex:attribute name="Task_Id" type="String" description="Task ID" assignTo="{!taskId}" />
<apex:attribute name="Cohort_Type" type="String" description="Cohort Type" assignTo="{!cohortType}" />
<apex:outputText value="{!taskId}"></apex:outputText><br/>
<apex:outputText value="{!cohortType}"></apex:outputText><br/>
<apex:repeat value="{!ScheduledCohorts}" var="s_cohorts" id="scheduledCohorts">
<tr>
<td width="70%">
<apex:outputText value="{!s_cohorts.Session_Name__c}"></apex:outputText><br/>
</td>
<td align="center" width="30%"><apex:outputLink value="{!s_cohorts.Session_URL__c}&accountId={!TaskAcct}&objectId={!taskId}">Register Here</apex:outputLink> </td>
</tr>
</apex:repeat>
</apex:component>
Controller
public class CohortRegisterController {
private List<Cohort__c> cohortsList;
private List<TASKRAY__Project_Task__c> taskList;
public TASKRAY__Project_Task__c taskObj {get; set;}
public String taskId {get; set;}
public String cohortType {get; set;}
private Boolean showLines {get; set;}
public CohortRegisterController() {
System.debug('cohortType ' + cohortType);
cohortsList = ([SELECT Id, Name, Display_Name__c, Session_Name__c, Start_Date__c, End_Date__c, Type__c, Status__c, Session_URL__c
FROM Cohort__c
WHERE Status__c in ('New', 'Scheduled') and Type__c = :cohortType
ORDER BY Start_Date__c]);
}
public String getTaskAcct(){
System.debug('taskId ' + taskId);
taskList = [Select Id, Name, Contact__c, TASKRAY__trAccount__c from TASKRAY__Project_Task__c Where Id = :taskId];
System.debug('taskList ' + taskList);
taskObj = taskList[0];
String taskAcct = taskObj.TASKRAY__trAccount__c;
System.debug('taskObj ' + taskObj);
return taskAcct;
}
public String getdotw(DateTime dateTimeVar){
DateTime dt = DateTime.newInstance(dateTimeVar.date(), dateTimeVar.time());
String dayOfTheWeek = dt.format('EEEE');
return dayOfTheWeek;
}
public Boolean getshowLines() {
if(!cohortsList.isEmpty()) showLines = true;
return showLines;
}
public List<Cohort__c> getScheduledCohorts() {
//List<Cohort__c> cohortsList;
System.debug('Cohorts');
System.debug('cohortsList ' + cohortsList);
return cohortsList;
}
}
Is there a way to see a debug log of the controller when an email is sent?
Can you see any reason using the :cohortType variable in my SOQL where clause would not evaluate correctly to the value passed in from the template?
Section from Template
<b>Study Island PLC Cohort Series Schedule and Registration Links:</b>
<table border="1" width="600" >
<tr><th>Cohort Description</th><th>Select Cohort</th></tr>
<c:CohortRegisterComponent Cohort_Type="{!RelatedTo.Program__c}" Task_Id="{!RelatedTo.Id}" />
</table>
Compponent
<apex:component controller="CohortRegisterController" access="global">
<apex:attribute name="Task_Id" type="String" description="Task ID" assignTo="{!taskId}" />
<apex:attribute name="Cohort_Type" type="String" description="Cohort Type" assignTo="{!cohortType}" />
<apex:outputText value="{!taskId}"></apex:outputText><br/>
<apex:outputText value="{!cohortType}"></apex:outputText><br/>
<apex:repeat value="{!ScheduledCohorts}" var="s_cohorts" id="scheduledCohorts">
<tr>
<td width="70%">
<apex:outputText value="{!s_cohorts.Session_Name__c}"></apex:outputText><br/>
</td>
<td align="center" width="30%"><apex:outputLink value="{!s_cohorts.Session_URL__c}&accountId={!TaskAcct}&objectId={!taskId}">Register Here</apex:outputLink> </td>
</tr>
</apex:repeat>
</apex:component>
Controller
public class CohortRegisterController {
private List<Cohort__c> cohortsList;
private List<TASKRAY__Project_Task__c> taskList;
public TASKRAY__Project_Task__c taskObj {get; set;}
public String taskId {get; set;}
public String cohortType {get; set;}
private Boolean showLines {get; set;}
public CohortRegisterController() {
System.debug('cohortType ' + cohortType);
cohortsList = ([SELECT Id, Name, Display_Name__c, Session_Name__c, Start_Date__c, End_Date__c, Type__c, Status__c, Session_URL__c
FROM Cohort__c
WHERE Status__c in ('New', 'Scheduled') and Type__c = :cohortType
ORDER BY Start_Date__c]);
}
public String getTaskAcct(){
System.debug('taskId ' + taskId);
taskList = [Select Id, Name, Contact__c, TASKRAY__trAccount__c from TASKRAY__Project_Task__c Where Id = :taskId];
System.debug('taskList ' + taskList);
taskObj = taskList[0];
String taskAcct = taskObj.TASKRAY__trAccount__c;
System.debug('taskObj ' + taskObj);
return taskAcct;
}
public String getdotw(DateTime dateTimeVar){
DateTime dt = DateTime.newInstance(dateTimeVar.date(), dateTimeVar.time());
String dayOfTheWeek = dt.format('EEEE');
return dayOfTheWeek;
}
public Boolean getshowLines() {
if(!cohortsList.isEmpty()) showLines = true;
return showLines;
}
public List<Cohort__c> getScheduledCohorts() {
//List<Cohort__c> cohortsList;
System.debug('Cohorts');
System.debug('cohortsList ' + cohortsList);
return cohortsList;
}
}
https://salesforce.stackexchange.com/questions/225310/pass-parameters-by-checking-some-condition-to-apex-controller
For your reference, you can check the below article too,
https://www.infoworld.com/article/3136743/how-to-pass-multiple-parameters-to-web-api-controller-methods.html
Thanks.