Here is my code:
Any thoughts why I'm getting this error?public expenseController(ApexPages.StandardController controller) { this.proj = (Expense_Report__c) controller.getSubject(); this.delivers = '[SELECT d.Name, d.Billable__c, d.Comments__c, d.Travel_type__c, d.Purchase_type__c, d.Expense_Report__c, d.Id, d.Purchase_Date__c, d.Quantity__c, d.Sales_Tax__c, d.Shipping__c, d.total__c, d.type__c, d.unit_price__c, d.Description__c,d.Price_Override__c,d.Override_Price__c'+ 'FROM Expense_Line_Items__c d' + 'WHERE d.Expense_Report__c = : proj.id' + 'Order by' + 'sortOrder' + 'DESC' + ']'; }
Hi Brian,Plese find the below modified code (Also added comments to understand it easily.)
Please do let me know if it helps you.Regards,public class expenseController {
// class variables
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
Expense_Report__c proj;
Expense_Line_Items__c[] delivers;
public string SelectedAccountId {get;set;}
String sortOrder {get; set;}
public expenseController(ApexPages.StandardController controller) {
sortOrder = ((sortOrder != null && sortOrder != '') ? sortOrder : 'Name');
// MD -- START
//String queryStr = (Expense_Report__c) controller.getSubject();
String queryStr = '[SELECT d.Name, d.Billable__c, d.Comments__c, d.Travel_type__c, '+ 'd.Purchase_type__c, d.Expense_Report__c, d.Id, d.Purchase_Date__c, '+
'd.Quantity__c, d.Sales_Tax__c, d.Shipping__c, d.total__c, d.type__c, d.unit_price__c, '+ 'd.Description__c,d.Price_Override__c,d.Override_Price__c FROM Expense_Line_Items__c d ' +
'WHERE d.Expense_Report__c = '+ proj.id +' Order by ' +sortOrder +' DESC ]';
// MD -- End
this.delivers = Database.query(queryStr);
}
public pagereference insertmethod() {
Expense_Line_Items__c cc = new Expense_Line_Items__c();
cc.Expense_Report__c = proj.id;
insert cc;
return null;
}
public Expense_Line_Items__c[] getDeliverables() {
return this.delivers;
}
// Action Method called from page button
public pagereference saveChanges() {
upsert this.delivers;
pageRef.setRedirect(true);
return pageRef;
}
// Action Method called from page link
public pagereference newDeliverable() {
Expense_Line_Items__c d = new Expense_Line_Items__c();
d.Expense_Report__c = this.proj.id;
delivers.add(d);
getDeliverables();
return null;
}
public pagereference DeleteAccount() {
// if for any reason we are missing the reference
if (SelectedAccountId == null) {
return null;
}
// find the account record within the collection
Expense_Line_Items__c tobeDeleted = null;
for (Expense_Line_Items__c a: this.delivers)
if (a.Id == SelectedAccountId) {
tobeDeleted = a;
break;
}
//if account record found delete it
if (tobeDeleted != null) {
Delete tobeDeleted;
}
pageRef.setRedirect(true);
return pageRef;
}
//Attachments
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public PageReference upload() {
if(Test.isRunningTest()){
Blob b = Blob.valueOf('Test Data');
attachment.Name = 'Name of the attachment';
attachment.body = b;
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = proj.id;
attachment.IsPrivate = false;
insert attachment;
pageRef.setRedirect(true);
return pageRef;
}
else
{
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = proj.id;
attachment.IsPrivate = false;
insert attachment;
pageRef.setRedirect(true);
return pageRef;
}
}
}
Mahesh