You need to sign in to do that
Don't have an account?

how to make custom object in Apex JSon format like javascript object
I have a javascript object that looks like this
this will be used in an ajax called in javascript data: JSON.stringify(address) and submitted
this will be used in an ajax called in javascript data: JSON.stringify(address) and submitted
var address = { location: { phoneNumber: "", address: { line1: $( "line1" ).val(), city: $( "city" ).val(), state: $( "state" ).val(), postalCode: $( "postalCode" ).val(), country: "US", } }, networks: ["1", "2","3","4","5"], company: "Salesforce" };
what I need to do is samething but in apex code with custom object but not sure how I can format it same way
qualRequest = new prequalAPI.QualificationRequest(); qualRequest.CustomerId = 0; qualRequest.PhoneNumber = 'STANDALONE'; qualRequest.AddressLine1 = addressLine1; if (unitType != null) { qualRequest.UnitType = unitType; } if (unitValue != null) { qualRequest.UnitValue = unitValue; } qualRequest.City = city; qualRequest.State = state; qualRequest.ZipCode = zip; qualRequest.Country = country; qualRequest.UnitType = unitType; qualRequest.RequestedNetworkNames = new List<String>(); qualRequest.RequestedNetworkNames.add('1'); qualRequest.RequestedNetworkNames.add('2'); qualRequest.RequestedNetworkNames.add('3'); qualRequest.RequestedNetworkNames.add('4'); qualRequest.RequestedNetworkNames.add('5'); JSON.serialize(qualRequest);my request status fails right now because json is not same format.
Defining a class structure, populating an instance of it and serializing the object would be ideal way of getting the JSON output.
Try the code below.
Feel free to add more attributes as you need.
Let me know if this helps.
All Answers
You need to generate inner class to replicate your JSON structure in apex code and populate values. Refer below sample code:
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Defining a class structure, populating an instance of it and serializing the object would be ideal way of getting the JSON output.
Try the code below.
Feel free to add more attributes as you need.
Let me know if this helps.