I have a Lightning Component controller doing the following:

  1. inserting a custom object Audit__c record via LightningDataService.
  2. on successful insert calls a server-side controller method, passing one String parameter, auditId.

The Server-Side controller then queries the database for an Audit__c record WHERE Id=: auditId. This query is returning 0 rows. I've validated that the string being passed to filter the query is indeed the correct Id of the newly created Audit__c record.

Why isn't the SOQL query picking up the new Audit__c record even when being fed the right Id (as String). Is there some sort of casting issue that is causing Apex not to match the String filter value to a record Id?

Client-Side Controller (1 & 2)

component.find("auditCreator").saveRecord(function(saveResult) {
    if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
        // record is saved successfully
        var resultsToast = $A.get("e.force:showToast");
            "title": "Saved",
            "message": "The audit was successfully initiated."

        var action = component.get("c.createAuditObjects");
        action.setParams({ auditId : JSON.stringify(saveResult.recordId)});

Server-Side Controller

public class initAuditReview {
    public static void createAuditObjects(String auditId){
        // auditId present
        System.debug('auditId is '+auditId);
        Audit__c parentAudit = [SELECT Id, Name FROM Audit__c WHERE Id=: auditId];

Debug Log

debug log

Proof of record existence:
record page in salesforce

  • 1
    Hi Nicholas, well asked question! As far as formatting goes, please note you can simply put empty lines between paragraphs (or a paragraph and a list/code block/etc.). You can also end a line with two spaces to create a line break. And use 1. instead of 1) to get <ol> formatting. See also: Markdown Editing Help.
    – Adrian Larson
    Commented Oct 19, 2018 at 7:35

1 Answer 1


There is an issue with auditId. If you will check debug log you are getting Id as "a03f200000oVeZRAA0". So just remove Json.stringify from client-side controller:

    action.setParams({ auditId : saveResult.recordId});

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .