You need to sign in to do that
Don't have an account?
Jos Vervoorn 2
List controller results by parent (case)
I'm working on a controller to list case related email.I'm struggling to get the SOQL query to limit results based on ParentID = case.id.
Without this everything works just fine.as a 'related' email list on the case page layout. What do I miss of what is wrong ?
The code of the controller:
public class CaseEmailListController {
public CaseEmailListController(ApexPages.StandardController controller) {
}
private ApexPages.StandardController stdCtrl {get; set;}
public List<Case> Cases {get; set;}
// Sorting on CreatedDate and ToAddress
private String sortOrder = 'CreatedDate';
public void sortByCreatedDate() {
this.sortOrder = 'CreatedDate';
}
public void sortByToAddress() {
this.sortOrder = 'ToAddress';
}
public Case ourCase {get; set;}
public List<EmailMessage> getCaseEmail() {
List<EmailMessage> results = Database.query(
'SELECT CreatedDate, FromAddress,HasAttachment,Id,ParentId,Subject,TextBody,ToAddress ' +
'FROM EmailMessage ' + 'WHERE ParentID=:' + Case.ID +
' ORDER BY ' + sortOrder + ' ASC ' +
'LIMIT 10'
);
return results;
}
}
Without this everything works just fine.as a 'related' email list on the case page layout. What do I miss of what is wrong ?
The code of the controller:
public class CaseEmailListController {
public CaseEmailListController(ApexPages.StandardController controller) {
}
private ApexPages.StandardController stdCtrl {get; set;}
public List<Case> Cases {get; set;}
// Sorting on CreatedDate and ToAddress
private String sortOrder = 'CreatedDate';
public void sortByCreatedDate() {
this.sortOrder = 'CreatedDate';
}
public void sortByToAddress() {
this.sortOrder = 'ToAddress';
}
public Case ourCase {get; set;}
public List<EmailMessage> getCaseEmail() {
List<EmailMessage> results = Database.query(
'SELECT CreatedDate, FromAddress,HasAttachment,Id,ParentId,Subject,TextBody,ToAddress ' +
'FROM EmailMessage ' + 'WHERE ParentID=:' + Case.ID +
' ORDER BY ' + sortOrder + ' ASC ' +
'LIMIT 10'
);
return results;
}
}
After some coffee, soda and debugging I managed to find the key.
String CaseId = ApexPages.currentPage().getParameters().get('id');
Jos/
All Answers
Hi Jos ,
Use the below code .
String q = 'SELECT CreatedDate, FromAddress,HasAttachment,Id,ParentId,Subject,TextBody,ToAddress ' +
'FROM EmailMessage '
+ 'WHERE ParentID=\'' +case.id+'\''+
' ORDER BY ' + 'FromAddress' + ' ASC ' +
'LIMIT 10' ;
System.debug('qqqqq'+q);
List<EmailMessage> mess = Database.query(q);
Thanks ,
Raj
After some coffee, soda and debugging I managed to find the key.
String CaseId = ApexPages.currentPage().getParameters().get('id');
Jos/