Hot answers tagged

11 votes

How to give date and time values in request body using postman

Use Pre-request script tab to save the date into a variable: var current_timestamp = new Date(); postman.setEnvironmentVariable("current_timestamp", current_timestamp.toISOString()); and then use it ...
Lucie Lavickova's user avatar
9 votes
Accepted

Can we insert multiple records in sObject using REST API post method without using apex class in workbench or postman

Create Multiple Records using rest API Documentation While the SObject Tree resource can be used to create nested records, you can also create multiple, unrelated records of the same type. In a ...
Ratan Paul's user avatar
  • 22.5k
8 votes
Accepted

Communicating between Lightning component and VF Page

Finallyyyyyyyy I figured out !!! I had set development mode on in my user profile**** because of which I was getting the following error. Uncaught DOMException: Blocked a frame with origin ...
Rao's user avatar
  • 16.7k
8 votes
Accepted

Not able to post data to Http with content type: application/x-www-form-urlencoded

I think you need to URL-encode the parameters in your payload. The password needs it in this instance, and it's worth doing for the username too. So, you would have: String payLoad = 'grant_type=...
Aidan's user avatar
  • 13.5k
7 votes

Read GET/POST parameters in apex class when service is called from external client

Rather than accept say form encoded parameters it is usually more convenient (for the client and in the Apex code) to accept a JSON string that holds the parameters. For the POST case: @HttpPost ...
Keith C's user avatar
  • 135k
7 votes

How to pass @httppost parameters in apex integration?

The only thing you need to do is retrieving body of the post request, this can be done like in the example below: @HttpPost global static void processPost() { Map<String, Object> ...
Mariia Illarionova's user avatar
6 votes
Accepted

How to insert multiple records in an object using REST API post method in workbench

Create Multiple Records using rest API Documentation While the SObject Tree resource can be used to create nested records, you can also create multiple, unrelated records of the same type. In a ...
Ratan Paul's user avatar
  • 22.5k
6 votes

Read GET/POST parameters in apex class when service is called from external client

If you want to test the REST API below: @RestResource (urlMapping='/wte/test/*') global class WTE_SampleRESTService { @HttpGet global static void doGet() { String id = RestContext....
Jitendra Zaa's user avatar
  • 3,102
6 votes
Accepted

RestResource Annotation - What is the urlMapping To?

That tells you the URL path. So when you want to hit your service you would use: /services/apexrest/CompanyData/
Adrian Larson's user avatar
  • 149k
5 votes

Send Blob file via Apex Rest Callout

You can't use both setBody and setBodyAsBlob in the same request. Also, if you're using multipart/form-data, you have to build a multipart payload. That means that you'll need to do something like the ...
sfdcfox's user avatar
  • 481k
5 votes
Accepted

How to properly send a Json in the body of a POST request?

As the documentation states, setBody accepts a String argument. In this case, you need to serialize the model. JSON2Apex payload = new JSON2Apex(...); request.setBody(JSON.serialize(payload)); I'd ...
Adrian Larson's user avatar
  • 149k
4 votes

How to give date and time values in request body using postman

I tried this in the workbench. It successfully created an event record. I suspect salesforce is expecting a date in a standard format instead of the date(value) format. { "Type":"contact call", ...
abhi's user avatar
  • 1,790
4 votes
Accepted

Cannot deserialize instance of datetime from VALUE_STRING value

Assuming the field is a date-time field, you've the wrong format. It should be in standard ISO 8601 format: {"req" : {"tickets": [{ "External_TicketID__c" :1853, "Date_Time__c": "2015-09-13T20:30:00....
sfdcfox's user avatar
  • 481k
4 votes

Send Blob file via Apex Rest Callout

Proper multipart/form-data POST requests from Apex are tricky. As @sfdcfox mentioned, you need to do some very careful manipulations between the 8-bit bytes of the input file and the 6 bit groups used ...
Daniel Ballinger's user avatar
4 votes
Accepted

Help with Rest Resource

You need to annotate your POST handler method with the @httpPost decorator. That way Salesforce knows to run that method when the REST Request method from outside is set to "POST". It should ...
John Thompson's user avatar
3 votes
Accepted

Send Blob file via Apex Rest Callout

Thanks for all of your valuable feedback. Below example worked for me with some modifications. How can I compose a multipart/form-data request? Here is my code. File Upload Method public void ...
MalindaL's user avatar
3 votes
Accepted

Attempting to use jQuery to POST to an external server from a Lightning Component

HTTP callouts are blocked by CSP (Contend Security Policy) by salesforce on purpose. The reason behind this are security concerns. You can try to make the callout in an serverside apex controller.
RichardT's user avatar
  • 129
3 votes
Accepted

Calling a flow through REST api returns "http body is required" error

flow expect input parameters while calling through API so you need to pass blank input array if you are not passing any value. Update your body with following json { "inputs": [ {} ] } So your ...
Himanshu's user avatar
  • 10.5k
3 votes
Accepted

Creating REST Api with little control over request structure

One method you could try would be to set up a public force.com site, and allow the public user access to your global Apex class. An alternative to that method is to set up an intermediary web server (...
Derek F's user avatar
  • 59.4k
3 votes
Accepted

POST Ajax method with Jquery to create new account contact and Opportunity

You can use the SObject Tree resource to create nested records. POST /services/data/v42.0/composite/tree/Account HTTP/1.1 Host: <instance>.my.salesforce.com Authorization: OAuth ... Content-...
sfdcfox's user avatar
  • 481k
3 votes

If we change the parameters used in webservice method in our org., will this cause error at end user consuming old WSDL?

Yes, Some WSDL has strictly typed XML validators, you change a single thing and hell break loose. It will break as it won't find the exact match for a method with exact parameters, it would just break ...
Pranay Jaiswal's user avatar
3 votes
Accepted

Can we use a map in HttpPost to make our code shorter? (too many fields and we can add more in future)

you can create create WrapperClass for Ticket, create JSON object and send it as param of request @HttpPost global static Ticket__c postT(TicketWrapper wrapper){ Ticket__c thisT = wrapper....
Oleksandr Berehovskyi's user avatar
3 votes
Accepted

post Event for a lead getting incorrect type for WhatId

You are supposed to use WhoId. WhoId: The WhoId represents a human such as a lead or a contact. WhoIds are polymorphic. Polymorphic means a WhoId is equivalent to a contact’s ID or a lead’s ID. The ...
Hemavantha Rajesh Varma Mudunu's user avatar
3 votes

rest post execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null

This error is fairly self-explanatory. You're passing a null value to EncodingUtil.urlEncode and that's not allowed. You only call that method at one location: req.setBody(',parameters: {LeadID='+...
David Reed's user avatar
  • 92.1k
3 votes
Accepted

dynamic json body as http post request

You need to pass the parameters to GetUrlRequest by changing it to method: public class RequestWrapper { public static GetUrlRequest GetUrlRequest(String cId, String sBC, String pur, abc abc, ...
salesforce-sas's user avatar
3 votes

How to Make Pardot Authorisation Request?

Not so long ago, Pardot changed the authentication method so that you can no longer put the username and password in the URL of the request. You need to put them in the request body. See the current ...
Aidan's user avatar
  • 13.5k
3 votes
Accepted

Unittest not covering webservice

As with any other method you want to cover, you have to actually call it. @IsTest static void myTest() { // setup as is Test.startTest(); DynamicApi.DynamicApiPost(); Test....
Adrian Larson's user avatar
  • 149k
3 votes
Accepted

System.TypeException: Invalid decimal in Rest Resource @HttpPost

The error is telling you exactly what is wrong. System.TypeException: Invalid decimal: 30,000 30,000 is not a valid numeric literal in Apex. (The comma, specifically, is disallowed). Consider ...
David Reed's user avatar
  • 92.1k
2 votes

To get a postData on apex page controller through custom url without reordering sequence of parameters

If your logic is in a Visualforce page then you can't get the raw post data. But you can include an "order" parameter that holds the other parameter names in the correct order separated by commas. ...
Keith C's user avatar
  • 135k
2 votes
Accepted

Rest Services using Apex class

How to deserialize a JSON String to Apex Use http://json2apex.herokuapp.com/ to generate you class and save that class in your salesforce org now in your rest service class @RestResource(...
Ratan Paul's user avatar
  • 22.5k

Only top scored, non community-wiki answers of a minimum length are eligible