4

I have created a force.com site to use as a webhook for getting a response from an external system to Salesforce. The response is coming in a JSON format. I am having trouble trying to get parameters in my class so that I can insert them in my related objects.

  • Can you show us some pieces of code that you have? What particular problem do you have? – rael_kid Jun 20 '13 at 13:12
1

sounds like a job for the REST API, have a look here http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_rest_code_sample_basic.htm

depending on the complexity of your JSON object you might be able to archive this by passing the values via apex:actionFunction and apex:param

have a look here: http://boards.developerforce.com/t5/Apex-Code-Development/How-do-I-pass-value-of-apex-inputField-to-Custom-Controller/td-p/532905

In a previous project I was working with a quite complex JSON object and tried to pass it via function and param to the Controller, but it was always null for the controller. I found a workaround by saving the JSON object in a Note record via API and just passing the Note ID to the controller

  • Seb__Wagner thanks for the reply but my issue is not send data from visualforce page to controller. Actually some other system hit my site url using POST method and post its data... I need to get this data in salesforce..and I am not getting it.. – Mahi Jun 20 '13 at 12:20
  • @Mahi sorry for the consufion, updated the answer – Seb Wagner Jun 20 '13 at 14:13
1

Create Site Url

append the /services/apexrest to the site url and create the webhook

After place the bellow code in your apex class

And call the class from your site url home page

@RestResource(urlMapping='/')

global class chargebee 
{     

   @HttpPost
   global static void doPost()
   {

        RestRequest req = RestContext.request;
        Blob body = req.requestBody;
        String bodyString = body.toString();    
        system.debug('====='+bodyString);           
   }      
}

You are done now...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.