Newbie to Salesforce. I have an object ExpenseItem which master detail relationship with another object Expense where Expense is the master.
I am trying to list expense items for a particular expense.
EDITED
Code in the apex class
try {
String parentId = 'xxx';
String sQuery = 'select id, Name from expenseItem__c WHERE expenseItem__c.expense__c.Id = :' + parentId + 'order by createdDate DESC';
List < sObject > lstOfRecords = Database.query(sQuery);
for (sObject obj: lstOfRecords) {
returnList.add(obj);
}
}
catch (Exception e) {
// "Convert" the exception into an AuraHandledException
throw new AuraHandledException('Error: '
+ e.getMessage());
}
finally {
// Something executed whether there was an error or not
}
The above code gives me variable does not exist error. Anything I am missing here? Can someone provide a simple example of how to get a child record filtered by the master id?
Best Answer
If you are passing hardcoded id ( Which you should not) then your query will look like
While if you have Id in some variable then your query will look like