0

I am getting AccountId as "Undefined" for some reason in sforce.connection.query.

try{ 

        var cons = sforce.connection.query("SELECT Id,Name,Accountid,Account.Name FROM Contact WHERE Id = '" + recordId + "'");

        var stats= cons.getArray("records");
        url +='&CF00N50000001oGFn='+stats[0].Name;
        url +='&CF00N50000001oGFd='+stats[0].Account.Name;
        url +='&CF00N50000001oGFd_lkid='+stats[0].Accountid;
        url +='&opp4='+stats[0].Account.Name;
        url +='&opp4_lkid='+stats[0].Accountid;

     var defaultValues = {
        'Name' : 'DV '+"-"+ today.getFullYear() + "-" + monthDigit + "-" + today.getDate(), 
        'AccountId':stats[0].Accountid,  
        'Donor_Account__c':stats[0].Accountid,  
        'Donor_Contact__c':stats[0].Id,  
        'retURL':'/006',
        'nooverride':'1'
    };

        alert(stats[0].Accountid);
    } 
  • Please edit your post to clarify what line throws this error and include the error verbatim. – Adrian Larson Aug 25 '17 at 19:02
2

It's AccountId, not Accountid (case sensitive). JavaScript is case sensitive, so you must always use the exact capitalization of the field.

  • @SantanuBoral If you're using a merge field, like {!Contact.accountid}, then yes, the parts between the {! and the } are not case sensitive. But doing it from a query via sforce.connection, it is indeed case sensitive. – sfdcfox Aug 25 '17 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.