0

been trying to have custom field in my opportunity . when the post happens I get the object in the right format however it doesnt post it, and doesnt really tell me the issue here is the object

accountInfoJson {"records":[{"attributes":{"type":"Account","referenceId":"acc1"},"name":"everything","billingstreet":"asdfasf\nundefined","billingcity":"TORRANCE","billingstate":"CA","billingpostalcode":"90275","Contacts":{"records":[{"attributes":{"type":"Contact","referenceId":"con1"},"firstname":"rerer","lastname":"rerer","Phone":"454654","Email":"23sdf@gmail.com"}]},"Opportunities":{"records":[{"attributes":{"type":"Opportunity","referenceId":"opp1"},"name":"everything","closedate":"2018-09-01","stagename":"Prospecting","Number_of_Seat_Trunks__c":"12","Voice_MRC__c":"20.00","Bandwidth_MRC__c":"20.00","Hardware_MRC__c":"20.00","CM_s_Quota_Value__c":"20.00"}]}}]}

the fields that are custom are all currency

here is my POST

var accountInfo = { "records": [{
   "attributes": { "type": "Account", "referenceId": "acc1" },
   "name": $( "input[id*='name']" ).val(),

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

   "Contacts": {
     "records": [{
       "attributes": { "type": "Contact", "referenceId": "con1" },
       "firstname": $('[id*="contactFirstName"]').val(),
       "lastname": $('[id*="contactLastName"]').val(),
       "Phone": $('[id*="contactPhone"]').val(),
       "Email": $('[id*="contactEmail"]').val()
     }]
   },
   "Opportunities": {
     "records": [{
       "attributes": { "type": "Opportunity", "referenceId": "opp1" },

        "name": $('[id="oppName"]').val(),
       "closedate": $('[id*="closedate"]').val(),
       "stagename": "Prospecting",
       "Number_of_Seat_Trunks__c": $('[id*="Number_of_Seat_Trunks__c"]').val(),
       "Voice_MRC__c": $('[id*="Voice_MRC__c"]').val(),
       "Bandwidth_MRC__c": $('[id*="Bandwidth_MRC__c"]').val(),
       "Hardware_MRC__c": $('[id*="Hardware_MRC__c"]').val(),
       "CM_s_Quota_Value__c": $('[id*="CM_s_Quota_Value__c"]').val()
     }]
   }
 }]
};
console.log('accountInfoJson ', accountInfo );

var accountInfoJson = JSON.stringify(accountInfo);
console.log('accountInfoJson ' + accountInfoJson );
$.ajax({    type: "POST",
    url: "/services/data/v42.0/composite/tree/Account",
    headers : {
        'Authorization' : "Bearer " + "{!$Api.Session_Id}" ,
         'Content-Type' : 'application/json'
                  },
       data : accountInfoJson,
       success : function(response){

                    console.log('response fasf sa fsf',response);
                            },
       error: function(response){
       console.log(response);
                    displayError(response);

                            }
                        });


            })

all I see in console is {readyState: 0, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}

Uncaught ReferenceError: displayError is not defined

0

You're putting numbers inside of quotes. You need to use parseFloat to get the correct values:

"CM_s_Quota_Value__c": parseFloat($('[id*="CM_s_Quota_Value__c"]').val())

Numbers must not be quoted in JSON in order to be valid. Your actual JSON should look like:

"CM_s_Quota_Value__c": 20.00,

Note that the number is not quoted.

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.