Hot answers tagged

9

The issue lies with the autogenerated GUID for the External/Customer Key (those names are interchangeable) and the Object ID GUID, which is not visible in the UI. For your particular call, if you are grabbing BBDD0F10-94A1-4CD6-B7A2-32FEB671E44F from the UI, then your API call should be https://www.exacttargetapis.com/hub/v1/dataevents/key:BBDD0F10-94A1-...


8

cURL is simply a command-line utility, written in C, that runs on a variety of binary platforms (Windows, Linux, Solaris, etc). Arguably, almost anything you can do with cURL you can do with Apex Code. Heroku can't readily determine a request from cURL versus Apex Code versus a telnet connection with the appropriate code copy-pasted from Notepad. What you ...


8

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 "https://praowin-dev-ed--c.gus.visual.force.com" from accessing a cross-origin frame. at EditAreaLoader.add_event As soon as I deactivated the development ...


7

Yes, the customer key in this case refers to the external key that's specified when you create the extension as shown below.


7

Glad you showed us everything you tried. You are really close, man! go to Setup > Remote Site Settings and create an entry for http://www.woopra.com/ create the following Visualforce Page and Apex Class, then view the page at /apex/Woopra see if you get a 403 like I do ;-) then substitute your real credentials into the request headers play until it gives ...


7

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 single request, you can create up to two hundred records. In the request data, you supply the required and optional field values for each record, each ...


5

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 single request, you can create up to two hundred records. In the request data, you supply the required and optional field values for each record, each ...


5

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 global static Result post() { String jsonString = RestContext.request.requestBody.toString(); // Use Apex JSON class to parse ... } For GET ...


5

Take a look at https://json2apex.herokuapp.com/ It was created by @Metadaddy & @Superfell and it works great for quickly generating APEX Classes to parse your json response into.


5

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 following: String body = ''; String boundary = 'ContentThatShouldNotAppearInTheBody'; Map<String, String> params = new Map<String, String> { '...


4

string test = 'test1,test1@gmail.com'; // which will be get from DB and make as CSV string String header = '--'+boundary+'\n'; //boundary is random string String footer = '\n\n--'+boundary+'--'; // blank line separates body/footer String bodyText = 'Content-Disposition: form-data; name="upload";\n' + 'filename="test.csv"\n' ...


4

I don't think you could keep the AJAX style callout, you'd run into cross-domain security issues. To keep it, you'd need an Apex based proxy anyway. You don't need to, and actually can't, use an @future in a Visualforce controller. But you can do the callout off the constructor. You can use the Apex JSON parser to handle the response: http://www....


4

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.


4

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 in the request body as follows: "ActivityDateTime": "{{current_timestamp}}"


4

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", "WhoId":"0032a000005oqGO", "Subject":"contact call created by api", "DurationInMinutes":"45", "ActivityDateTime":"2018-03-29" } If you need to ...


4

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 by Base64 encoding. I've written about this in some depth in Steps required to support POSTing multipart/form-data Content-Type from Apex. You might find it ...


4

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=password' + '&username=' + EncodingUtil.urlEncode('test@ad.abc.com','UTF-8') + '&password=' + EncodingUtil.urlEncode('O$Q3tz%Hdkqq', 'UTF-8') + '&...


4

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> requestBody = (Map<String, Object>) JSON.deserializeUntyped(RestContext.request.requestBody.toString()); //do something with the resulting map - this is the ...


4

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 look like this: @httpPost global static String NewLead(...){...} Here's the Documentation


3

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.request.params.get('id'); System.debug('ID: '+ id); } @HttpPost global static void doPost(String id, String name) { System.debug('ID: '...


3

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.000Z" }, { "External_TicketID__c" :26554, "Date_Time__c": "2015-09-13T22:30:00.000Z" } ]}} As a side note, make sure that External_TicketID__c is indeed a ...


3

This pattern where you explicitly update the RestContext allows you to set the status value: @HttpPost global static void doPost() { // Do stuff RestResponse res = RestContext.response; if (res == null) { res = new RestResponse(); RestContext.response = res; } // Return something res.responseBody = Blob.valueOf(...


3

The Force.com REST API and Apex REST are not the same thing. The first is provided by the platform to interact with objects and the second is written by a developer in Apex to interact via a custom implementation. So in short, the platform's REST API can accept a multipart binary but you cannot code your own Apex class exposed as a @RestResource and do the ...


3

You can't "overload" rest methods. Each method must map to exactly one function. You'll have to either use two functions with different names, or one method that checks the number of parameters and makes the appropriate function call.


3

I was missing the following line of code: request.setHeader('Content-Type', 'application/json'); Once I added it under the request.setBody(Body); line, it worked like a charm.


3

That tells you the URL path. So when you want to hit your service you would use: /services/apexrest/CompanyData/


3

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 (either on physical hardware that you/your company/your client has on-premise, or through something like AWS, DigitalOcean, or Heroku). You would point this ...


3

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-Type: application/json Accept: application/json Content-Length: ... { "records": [{ "attributes": { "type": "Account", "referenceId": "acc1" }, "name": "...


3

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 Refer Point 2. Thus you have to share your Updated WSDL with the third party everytime you change your parms. Is there a hack for this? Yes there is. ...


3

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.converttoSobject(); insert thisT; return thisT; } global class TicketWrapper{ public String title {get; set;} public String whattime {get; set;} ...


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