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
Deepak Singh 116Deepak Singh 116 

Need to create below JSON from field value of different objects and send request to external system.

I am new in integration. Please find the below JSON sample request.I need to create JSON like this and send request to external system and need to save the reponse from external system.Pleae Help.
  "userCredentials": {
    "userId": "Sample USer",
    "userPassword": "PAssword",
    "source": "MOBILE",
    "sourceId": "358156078472543",
    "initiatedBy": "ADMIN",
    "deviceName": "SM-J200G",
    "deviceVersion": "22",
    "sourceVersion": "",
    "latitude": "28.61929",
    "longitude": "77.3784",
    "address": "A-118, A Block"
  "stageLeadDetails": {
    "txnType": "LEAD",
    "loanType": "NEW",
    "loanSubType": "NOR_NA",
    "operationType": "LEAD",
    "monthlyIncome": 25000,
    "obligation": 0,
    "dafaultEmi": 0,
    "dafaultLoanAmount": 50000,
    "dafaultFoir": 0,
    "mobileAppVersion": "",
    "salesId": "MADMIN911",
    "salesSequenceNo": 911,
    "loanPurpose": "HL",
    "loanPurposeDesc": "Home Loan",
    "lifeInsurance": "Y",
    "loanProductsInsurance": "Y",
    "propertyInsurance": "Y",
    "leadFinalScore": 0,
    "mobileDealId": 911,
    "imeiNumber": "860998036081713",
    "amountRequired": 50000,
    "finalRate": 15,
    "longitude": "28.6192979",
    "latitude": "77.3784688",
    "locationAddress": "A-118, A Block, Sector 63, Noida, Uttar Pradesh 201307, India Noida Uttar Pradesh India 201307 A-118",
    "tenure": 120,
    "product": "HC",
    "productDesc": "HOME CONSTRUCTION LOAN",
    "scheme": 6,
    "rateType": "E",
    "branchId": "7",
    "leadGenerationCity": "UDAIPUR",
    "apf_napf": "",
    "iir": 3.23,
    "foir": 3.23,
    "emi": 807,
    "nearestBranch": 1,
    "leadMakerId": "ADMIN",
    "leadGenerationDate": "2018-10-16",
    "leadMakerDate": "2018-10-16",
    "leadGeneratedRm": "ADMIN",
    "dealSourceType": "ADVERTISE",
    "dealSourceName": "HGCH",
    "makerDate": "2018-10-16",
    "propertyCurrentStatus": "",
    "householdMonthlyIncome": 0,
    "customerRoleList": [
        "salesId": "MADMIN911",
        "customerRole": "PRAPPL",
        "makerDate": "2018-10-16",
        "customerDtl": {
          "salesCustomerId": "3",
          "salesId": "MADMIN911",
          "existingCustomerId": 0,
          "customerExistingType": "N",
          "salutation": "DR",
          "cibilId": "",
          "lastBureau": "NA",
          "photoStream": "",
          "customerConstitution": "SEASDINCO",
          "customerConstitutionDesc": "SELF EMPLOYED ASSESSED INCOME",
          "residentialStatus": "RESIDENT",
          "castCategory": "ST",
          "castCategoryDesc": "SCHEDULE TRIBE(ST)",
          "firstName": "ABHI",
          "middleName": "",
          "lastName": "SINGH",
          "gender": "MALE",
          "genderDesc": "MALE",
          "emailId": "",
          "alternateEmailId": "",
          "customerDOB": "1978-01-07",
          "customerCategory": "GOLD",
          "customerCategoryDesc": "GOLD",
          "maritalStatus": "S",
          "maritalStatusDesc": "SINGLE",
          "community": "",
          "husbandName": "",
          "naregaNo": "",
          "educationDetail": "PRO",
          "educationDetailDesc": "PROFESSIONAL",
          "isMobileVerified": "N",
          "isEmailVerified": "N",
          "isPanVerified": "",
          "pan": "BODPM4246E",
          "drivingLicense": "",
          "voterId": "",
          "passportNumber": "",
          "aadharNumber": "",
          "customerType": "I",
          "turnover": 0,
          "monthlyIncome": 25000,
          "fatherHusbandName": "FATHER",
          "motherName": "MOTHER",
          "guaranteeAmount": 0,
          "numberOfDependent": 0,
          "makerDate": "2018-10-16",
          "stageAddressDtlList": [
              "salesId": "MADMIN911",
              "bpType": "CS",
              "addressType": "REI",
              "addressTypeDesc": "CURRENT RESIDENCE",
              "addressLine1": "ADDRESS",
              "addressLine2": "",
              "addressLine3": "",
              "pincode": "110011",
              "tehsil": 32574,
              "tehsilDesc": "Udyog Bhawan S.O",
              "district": 122,
              "districtDesc": "CENTRAL DELHI",
              "state": 10,
              "stateDesc": "DELHI",
              "country": 1,
              "countryDesc": "INDIA",
              "stayingTogether": "",
              "addressDetail": "REL",
              "monthlyRent": 0,
              "stdCode": "",
              "phoneNo": "",
              "mobileNo": "8802738748",
              "communicationAddress": "Y",
              "landmark": "LANDMARK",
              "areaName": "",
              "noOfRooms": 0,
              "periodStay": 0,
              "noOfYears": 5,
              "noOfMonths": 0,
              "plotNo": "",
              "floorNo": "",
              "makerDate": "2018-10-16"
    "deviceName": "SM-J200G",
    "deviceVersion": "22"
  "leadSubmissionType": "LEAD"
{"operationStatus":"1","operationMessage":"Operation Completed Successfully. ","salesLeadId":"19761","applicationForm":null,"loanPurposeMakerDate":"2019-01-07 16:40:50"}
Hi Deepak,

Please find the tutorial to generate APEX class from JSON and also to write test classes.
This is another community thread on the same topic :

Please mart this as SOLVED if it had helped you. Thanks!

Krishna Avva
Deepak Singh 116Deepak Singh 116
Thanks krishna for your reply .
But i need to craete JSON like the above questiona and send it to exteral system.
Please help me.
Hi Deepak,

Please use the JSONGenerator class to use only in the format mentioned. Please find the example and additional details here :

But I would strongly suggest that you use JSON2APEX, generate the respective APEX classes and utilize them for callouts from a maintenance point of view.

Krishna Avva