• Akash Singh 77
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi Everyone,
     I am taking baby steps towards REST apex  functionalliy and have developed some code (which fortunately woorks). Now I need your help in enhancing its operations. Please find the summary given below:

Using a json (given below) I managed to create an account record in salesforce:

{
   "acct":
   {
     "Name":"Jag"
   }

}

Apex Code:
@RestResource(urlMapping='/v1/accounts/*')
global with sharing class MyRestResource {
@HttpPost
    global static AccountWrapper doGet(Account acct) {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        AccountWrapper response= new Accountwrapper();
        try{
         insert acct;
         response.message='Mogamgo Khush Hua :)';
        }
        catch(Exception exc){
         response.message='Mogamgo Dukhi Hua :('; 
        }
       return response;
    }
      global class AccountWrapper {
      public Account acct;
      public String status;
      public String message;
      public AccountWrapper(){}

    }

}
Now I want to modify my apex code so that it can take a json with 1 account and 3 contacts in it and insert them in salesforce. Sample json is given below , can anyone please guide me with the modifications that are to be done in my apex class?


{
  "rqst":{
        "acct":{
         "Name":"Jag"
        }
        "conlist":{
         [
           {"FirstName":"Test","LastName":"Test"},
           {"FirstName":"Test1","LastName":"Test1"}
         ]
        }
  }

}