[SalesForce] SOQL query for Master detail relationship filtered by master record ID

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

[select id, Description from expenseItem__c where expense__c = 'parentExpenseId' order by createdDate DESC];

While if you have Id in some variable then your query will look like

Id parentRecordId = 'SomeValueHere';
[select id, Description from expenseItem__c where expense__c =: parentRecordId  order by createdDate DESC];