I am trying to submit Account address using javascript by SObject Tree, I am not sure what I am doing wrong for account address object here is the object

   var accountInfo = { "records": [{
   "attributes": { "type": "Account", "referenceId": "acc1" },
   "name": $( "input[id*='name']" ).val(),
   address: {
       "records": [{
   "line1": $( "input[id*='pqStreet']" ).val(),
   "line2": { type: $("select[id*='unType']").val(), value: $("input[id*='unValue']").val()},
 "city": $( "input[id*='pqCity']" ).val(), 
 "state": $( "[id*='pqState'] option:selected" ).val(), 
 "postalCode": $( "input[id*='pqZip']" ).val(),
   "Contacts": {
     "records": [{
       "attributes": { "type": "Contact", "referenceId": "con1" },
       "firstname": "John",
       "lastname": "Doe"
   "Opportunities": {
     "records": [{
       "attributes": { "type": "Opportunity", "referenceId": "opp1" },
       "name": "Closing Soon",
       "closedate": "2018-09-01",
       "stagename": "Prospecting"

You're trying to define the address as if it were a "child" record (you have the "child relationship name" followed by an array of "records"). Instead, you should refer to the fields as their proper API names:

"billingstreet": $( "input[id*='pqStreet']" ).val()+'\n'+ 
"billingcity": $( "input[id*='pqCity']" ).val(),
"billingstate": $( "[id*='pqState'] option:selected" ).val(), 
"billingpostalcode": $( "input[id*='pqZip']" ).val(),

I'm not sure I've understood the intent of how you have the billing street laid out, so you'll need to tweak the code accordingly.

| improve this answer | |
  • is the shipping address same thing? – Metawaa Mar 2 '18 at 18:26
  • 1
    @Metawaa It's a different set of fields. It really depends on the purpose. Billing is typically where bills are sent, shipping is where stuff is shipped to. Most places use the same address for both, but it may not necessarily be so. Use whichever your organization expects the data to be in. – sfdcfox Mar 2 '18 at 18:28

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.