function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kumar5Kumar5 

wrapper class to map json to salesforce

Wrapper class for mapping JSON Values
Hi Team,

I am workin on Webservices where i need to map json to salesforce. 

Please help me with the sample code for following json {
    "QuoteLineItem": [
        {
"REQ_ID": "055",
            "QUANTITY": "21168.000",
            "ITEM_UNIT_PRICE": "292.48",
            "REQ_PRICE_PER": "100",
            "STATUS": "8",
            "UOM": "PC",
            "CURRENT_PRICE": "292.48",
            "ITM_NUMBER": "000001",
            "CURRENT_PRICE_UOM": "PC",
            "MATERIAL": "5-103669-3"
        },
        {
            "REQ_ID": "055",
            "QUANTITY": "21168.000",
            "ITEM_UNIT_PRICE": "292.48",
            "REQ_PRICE_PER": "100",
            "STATUS": "8",
            "UOM": "PC",
            "CURRENT_PRICE": "292.48",
            "ITM_NUMBER": "000001",
            "CURRENT_PRICE_UOM": "PC",
            "MATERIAL": "5-103669-3"
        }
    ],
    "QuoteHeader": {
        "POS_REGION": "",
        "NET_VALUE": "0.00",
        "END_ACCT": "",
        "REC_VERSION": "02",
        "REQUESTOR_NAME": "",
        "REQUESTED_DATE": "00000000",
        "PARTDETAILS_CNT": "100",
        "REQUESTOR_EMAIL": "",
        "EFFECTIVE_DATE": "20160713",
        "BRANCH_ID": ""
    },

}



public class QuoteWrapper {


tried this the below one but getting Unknown field: QuoteWrapper.QuoteLineItem
public class QuoteWrapper {
    public class QuoteHeader{
        public String CUST_REF_NO {get; set;}
        public string SALES_OFFICE {get; set;}

        public Integer invoiceNumber {get; set;}
        public List<quotelinteitem> quotelinteList {get;set;}
      
    }
    
    Public Class quotelinteitem{
        Public String QUANTITY;
        
      }

    public List<QuoteHeader> QuoteList {get; set;}

}

Thanks,
Kumar
Khan AnasKhan Anas (Salesforce Developers) 
Hi Kumar,

Greetings to you!

Below is the sample code.
 
public class JSON2Apex {

	public List<QuoteLineItem> QuoteLineItem;
	public QuoteHeader QuoteHeader;

	public class QuoteLineItem {
		public String REQ_ID;
		public String QUANTITY;
		public String ITEM_UNIT_PRICE;
		public String REQ_PRICE_PER;
		public String STATUS;
		public String UOM;
		public String CURRENT_PRICE;
		public String ITM_NUMBER;
		public String CURRENT_PRICE_UOM;
		public String MATERIAL;
	}

	public class QuoteHeader {
		public String POS_REGION;
		public String NET_VALUE;
		public String END_ACCT;
		public String REC_VERSION;
		public String REQUESTOR_NAME;
		public String REQUESTED_DATE;
		public String PARTDETAILS_CNT;
		public String REQUESTOR_EMAIL;
		public String EFFECTIVE_DATE;
		public String BRANCH_ID;
	}

	
	public static JSON2Apex parse(String json) {
		return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
	}
}

Please check below tools for JSON to APEX.

https://json2apex.herokuapp.com/

https://www.adminbooster.com/tool/json2apex

http://json2apexengine.somee.com/

Also, please refer to below link which might help you further.

http://blog.deadlypenguin.com/blog/2015/11/30/json-deserialization-in-salesforce/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas