Questions tagged [callout]

"HTTP Callouts" connect to a remote web server from Apex code.

Filter by
Sorted by
Tagged with
80
votes
2answers
13k views

Has anyone, ever, successfully invoked the Metadata API from within Apex?

While researching a semi-related question posted here earlier, I dug up some interesting and conflicting information regarding whether it's even possible to use the Metadata API from within Apex. I ...
34
votes
2answers
30k views

HTTP Callout from Triggers

I have a trigger on the Custom Object that calls a class. That class makes an HTTP GET request to a Web Service. However I get the following error: Callout from triggers are currently not supported. ...
31
votes
6answers
28k views

Testing HttpCallout with HttpCalloutMock and UnitTest Created Data

We have a callout to an external webservice that requires retrieving some data from the database via SOQL and then issuing an HTTP GET request, and performing various logic based upon the response. ...
29
votes
5answers
17k views

Workaround for the 10 web service callout limit in apex?

What are the workarounds for the 10 web service callout limit in apex. If you need to make, say 50 callouts, how do you batch them so that you can execute them all asynchronously? Is there a good ...
24
votes
5answers
17k views

Unit Test: You have uncommitted work pending. Please commit or rollback before calling out

So I have a method that takes as a parameter an Id of a object and uses it to make an external callout. Unfortunately I can't seem to figure out any way to test it. @isTest static void ...
23
votes
4answers
6k views

Unit tests that need more than one WebServiceMock

I'm dealing with an odd situation where I need to call Webservice A to authenticate to Webservice B and Webservice C, all with different endpoints. I know how to setup mocks to test B and C ...
22
votes
2answers
3k views

Where to Store Token Auth?

Problem Statement I am working on an integration that will authenticate with a token. I need to pass it via header as follows: "Authorization": "Token abcdefghijklmnopqrstuvwxyz" I also need to ...
22
votes
2answers
3k views

Can we callout and chain a Queueable class?

I'll jump right into some code: public class ChainQueue implements Queueable, Database.AllowsCallouts { public void execute(QueueableContext context) { if(QueueUtil.hasNext()) { ...
21
votes
2answers
10k views

How can I make a PATCH HTTP Callout from Apex?

I need to make a PATCH http request. I made the rather incredible discovery today that I can't set an HttpRequest to use the PATCH method, as when sending the request I get a callout exception: ...
20
votes
1answer
32k views

How do I handle a 302 redirect response to my HTTP callout?

I am accessing an API, but when i debug the response it shows this message [Status=Moved Temporarily, StatusCode=302]. what should i do to access my required response.. my code is given below public ...
20
votes
3answers
4k views

AWS Signature (version 4) in Apex

Over the past few days I have been struggling to create the AWS signature version 4 in Apex to send a request via query string, I have followed the step-by-step instructions for signing aws requests, ...
18
votes
2answers
5k views

WebServiceMock causing “CalloutException: You have uncommitted work pending” when creating managed package

I have a number of test methods that call Test.setMock(WebServiceMock.class, new SomeWebServiceMockImpl()); where SomeWebServiceMockImpl implements WebServiceMock. These test methods pass when I run ...
17
votes
1answer
858 views

Apex Framework / library for consuming REST services

To consume REST services there is a lot of boilerplate code needed: Build Apex Objects to model the responses Code to deserialize REST responses to those classes Handling of HTTP requests, responses ...
15
votes
2answers
5k views

How do you write a unit test for a trigger whose only function is to make a callout?

What is considered a best practice for writing a unit test (to maintain code coverage) on a trigger whose sole function is making a callout (Which also means it has to use a future method)? Neither ...
15
votes
3answers
6k views

Challenge with unit tests, mock callouts and running as a user

Background I am developing a number of business applications within a community. Many of these apps rely on callouts to another ERP system to verify or retrieve or push data. In order to adequately ...
14
votes
1answer
2k views

Access MetadataAPI via JavaScript

We created an 100% native Salesforce IDE as a Managed Package which is using ToolingAPI and MetadataAPI via APEX. This works fine. But there is one thing which really bothers people after the ...
13
votes
1answer
3k views

Use a Named Credential with API key?

I want to be able to make callouts to JotForm, but they do not support OAuth and username/password is insufficient for their API. Here are their docs; for reference, here are the 3 auth options: ...
12
votes
3answers
16k views

Post multipart without Base64 Encoding the body

I am trying to POST a PDF attachment to a Restful web service (not under my control). My issue is that I need to get put the raw bytes of the PDF into the Body of the request and whenever I call Blob....
12
votes
1answer
10k views

Error System.CalloutException: Callout from scheduled Apex not supported

i have created a schedulable class which has to trigger a batch job. The run method for the batch class will get list of data to process from a webservice callout. Now, i got the exception below. Any ...
12
votes
1answer
1k views

How do I unit test code that includes a callout?

This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through ...
12
votes
1answer
1k views

Managed package callout invoked from managed package extension causing test class failure

We have a managed package that has executes a HTTP callout from a trigger that calls a future method on the insertion of new records on a particular object. We have a managed package extension that ...
12
votes
2answers
11k views

Call webservice with NTLM authentication

Is it possible calling a webservice using NTLM authentication from apex? It is a microsoft navision webservice, I tried to do it in java following this guide and it works.
12
votes
1answer
3k views

Testing Batch Job with HTTP Callouts

Suppose I have the following: global class CMBatchRegisterUsers implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful { global final String orgID = UserInfo....
11
votes
1answer
2k views

Uncommitted work pending in unit test with trigger and queueable callout

I have an after insert trigger that invokes queueable Apex which makes a callout. The trigger and callout work fine in the UI and I don't get any errors in normal operation. However, my unit test ...
11
votes
1answer
1k views

BURP Scanning a managed package

Salesforce have asked me to do a BURP Scan on my managed package before I submit it to the AppExchange. My Managed Package is built on the Force.com platform. It does perform a couple of callouts to ...
11
votes
2answers
4k views

System.CalloutException: Unable to tunnel through proxy (Winter '16 issue)

This morning I'm seeing sporadic failures across the board for our various integrations in production. When using HTTPRequest callouts, a System.CalloutException is being thrown with the following ...
11
votes
2answers
3k views

Sorting Opportunity Line Items programmatically

I've been attempting to do a purely Apex based sorting of Opportunity Line Items based on a solution I found in the Salesforce developer boards. That solution uses a combination of Javascript and Apex ...
11
votes
0answers
1k views

Including access token in endpoint URL when using named credential in REST callout

I'm trying to retrieve a list of forms using the FormAssembly API via a HTTP Request to the endpoint: https://app.formassembly.com/api_v1/forms/index.json I was able to setup named credentials and ...
10
votes
3answers
7k views

Too many callouts: 1 in Salesforce Batch

When i am sending one HTTPRequest it's giving error : System.LimitException: Too many callouts: 1 Don't understand why...pls help me out. Thanks! Here is my code: global class ClassName ...
10
votes
2answers
940 views

Does queueing a future method count as DML?

We need to implement the following pattern at my org: callout to external data source if that callout takes too long (according to some configurable threshold), log an error (ie do some DML) if that ...
10
votes
2answers
376 views

Guarantee only a single asynchronous job runs at a time

This is a bit of an odd one. We are interacting with an external system that does not support concurrency due to a bug which they are struggling to fix. We perform a HTTP callout, the callout takes ...
10
votes
2answers
2k views

Is there a simple way to serialize execution of Batchable class?

I need to Geocode addresses on Account using an HTTP callout; the webservice will only service one address per callout. For this use case it is preferable to geocode the accounts immediately, rather ...
10
votes
1answer
2k views

Callouts to Retrieve Attachments

We are working on exposing some internal services to Salesforce. One of the things we would like to do is retrieve PDFs from a SOAP web service. I'm trying to figure out what format Salesforce can ...
10
votes
4answers
2k views

Chaining @future methods

Is there any way/workaround at all to call a future method immediately from another future event? If not what's the fastest way to call my future method indirectly? I basically have a 3rd party ...
10
votes
1answer
695 views

Testing callout with zipped static resource

How can I access the content of a static resource zip file to create several callout mocks? I'd like to group all service responses in a single zip file without create several static resources. In ...
9
votes
1answer
1k views

Named Credentials and support for the OAuth2 Client Credentials Grant Type and alternatives

I have a requirement to authenticate to an external API for callouts using the OAuth2 Client Credentials Grant (This was helpful in referencing the different grant types for me). I would like to use ...
9
votes
2answers
390 views

Tooling API in Apex - polymorphism, generic query() callout?

I am working on Salesforce project heavily depending on use of Tooling API (we are executing tests on remote SF organizations and gathering results). What bothers me is I cannot use polymporphism ...
8
votes
2answers
508 views

Why aren't iterators in batch jobs lazy-loaded?

I have a batch job that needs to callout to an external web service and retrieve a variable number of records. Seems like a perfect use-case to have an iterator which performs the callouts until there ...
8
votes
1answer
3k views

What can cause “System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out”?

What else, other than insert/update/upsert/delete, can cause "System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out"? I've search the debug logs ...
8
votes
2answers
4k views

Making a Http GET callout to internal Salesforce URL

I have a Salesforce VisualForce page that pretty much just Outputs XML: https://[mynameserver]/Apex/[myxmlpage] I want to expose a WSDL service where I am pretty much just going to wrap the ...
8
votes
1answer
799 views

HTTP Callout Problems in Pre-release

I am running the same code in two different environments and I am getting different results. I have the following code hitting the REST API exposed on StackExchange: Http httpQuestions = new Http(); ...
8
votes
1answer
10k views

Why do I get 'PKIX path building failed' exception with my callout?

Error message :PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target Hello all please see the above ...
8
votes
2answers
806 views

How to set an HttpCalloutMock to reply differently on subsequent requests to the same endpoint?

I'm building a Queueable that consumes an Azure service bus queue. Every call to the endpoint gives me one message so I keep on calling that same endpoint until I get a 204. The method that calls the ...
8
votes
2answers
2k views

Salesforce call Heroku Web Service

We have a salesforce application, and the application triggers a callout to a heroku service that gathers some data from a third party database. After gathering and processing the data from the third ...
8
votes
1answer
588 views

Considerations for calling out to enterprise applications behind a firewall from salesforce?

If I'm looking to integrate an enterprise application behind a firewall with Salesforce, what considerations should I be making? From the architect certification study guide Given a scenario, ...
8
votes
2answers
8k views

web service callout failed error

I'm having an issue with the Address Verification method available through StrikeIron. I imported the following WSDL and am using the generated wsdl2apex code. The WSDL I'm using is here: http://...
8
votes
1answer
794 views

Calling a Callout via @future still gives uncommitted work pending error

Class A is simple page controller. It creates an instance of Class B. The user can click a button on a VF page to invoke a pagereference method in Class A that will invoke various methods in class B, ...
8
votes
2answers
440 views

Callout from a future event

I have a managed app that does a callout (REST API POST) on Account save. The managed app is developed by a 3rd party that we have no control of. The callout creates a future event which gets an id ...
8
votes
1answer
512 views

What would be the proactive steps that we need to take when salesforce disables SSL and enables TLS?

I heard that salesforce would stop the support for SSL 3.0 and will enforce TLS 1.0 and higher. https://help.salesforce.com/apex/HTViewSolution?urlname=Salesforce-disabling-SSL-3-0-encryption From ...
7
votes
2answers
5k views

HttpCallout resulting Html response instead of JSON

I am trying to make a httpcallout to "https://www.carrierlookup.com". When I tried it with browser's apex rest client extension it returned correct response : {"Response":{"creditBalance":"985","...