You need to sign in to do that
Don't have an account?
smita bhargava
object design for the json data
Hello
I have json data as follows.
I need help in creating an object design for this json data so when I deserialize the json then I want to store in backend.
Please help me in creating the object design.
smitaB
I have json data as follows.
I need help in creating an object design for this json data so when I deserialize the json then I want to store in backend.
Please help me in creating the object design.
{ "invoiceList": [ { "totalPrice": 5.5, "statementDate": "2011-10-04T16:58:54.858Z", "lineItems": [ { "UnitPrice": 1, "Quantity": 5, "ProductName": "Pencil" }, { "UnitPrice": 0.5, "Quantity": 1, "ProductName": "Eraser" } ], "invoiceNumber": 1 }, { "totalPrice": 11.5, "statementDate": "2011-10-04T16:58:54.858Z", "lineItems": [ { "UnitPrice": 6, "Quantity": 1, "ProductName": "Notebook" }, { "UnitPrice": 2.5, "Quantity": 1, "ProductName": "Ruler" }, { "UnitPrice": 1.5, "Quantity": 2, "ProductName": "Pen" } ], "invoiceNumber": 2 } ] }Thanks
smitaB
I got your point and this is what I would suggest
Create a master detail relationship between Invoice and Invoice Line Item and the field and field types will be as follow
Invoice:
- totalPrice :Roll Up Summary field on the price field of Invoice
- statementDate: Date time field
- invoiceNumber:Number type Field
Invoice Line Item:- UnitPrice: Currency or Number Field
- Quantity: Number Field
- ProductName:String
Hope this helps,Sandeep
All Answers
You would need to create a Wrapper class. I have created this wrapper using the JSON provided by you:
The comments describe the the data that was provided. Please note that you can use online tools such as JSON to Apex (https://www.adminbooster.com/tool/json2apex) to create Apex classes from JSON data in future.
Please follow this example (https://salesforce.stackexchange.com/questions/9328/how-to-parse-the-json-object-in-salesforce) to further deserialse your JSON.
Hope this helps,
Sandeep
I understand the wrapper class, but I am purely looking at object design.
for ex: I consider invoice to be an object having three fields i.e totalprice , statementdate and invoicenumber.
so in backend , for every invoice nunber I want to have the line items i,e Unitprice,Quantity,ProductName
so should I design lineitems as a separate object having a lookup to Invoice .
I hope I am clear.
Thanks
smita
Run the following: After instantiating something like the following:
Hope this helps.
John
I am new to salesforce so I take some time to understand.
so invoice is one object and lineitems is another object.
for every invoice number , I need the line items at the object level.
then how to relate both objects?
Thanks
smita
I got your point and this is what I would suggest
Create a master detail relationship between Invoice and Invoice Line Item and the field and field types will be as follow
Invoice:
- totalPrice :Roll Up Summary field on the price field of Invoice
- statementDate: Date time field
- invoiceNumber:Number type Field
Invoice Line Item:- UnitPrice: Currency or Number Field
- Quantity: Number Field
- ProductName:String
Hope this helps,Sandeep
You have a few options. You can activate quotes and use them as invoices or create a custom invoice object and a line item detail object with a master detail relationship between the invoice and line item detail. The master detail field ties them together.
Regards,
John
Thanks I got the picture. Actually this is what I wanted.
Thanks
smita
Thanks for the input.
I will try with quotes also.
Thanks
smitaB