Hot answers tagged

5

I would do something like, 1) Do callout in start method, and store the access token in a class-level variable. 2) In order to maintain state for a class level variable I would make Batch as Stateful 3) execute can use access token from class variable 4) Finish method can again do callout to invalidate the accesstoken. (Even if you dont do this, the ...


5

I just had a similar requirement that I'm filling by using Platform Cache to hold the token and its expiration timestamp. It looks basically like this: public class WSAuthentication { public static string getSessionToken() { String token = (String)Cache.org.get('wsToken'); Datetime expires = (Datetime)Cache.org.get('wsExpiration'); ...


3

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, cbl cbl){ return new GetUrlRequest(cId,sBC,pur,abc,cbl); } public class abc { public String ab; public String cd; public ...


3

The answer is "yes". There are a number of different ways to deal with it, depending on the UX you want, how this process should be initiated and the level of coding you are happy to do. My immediate recommendation would be to use a Screen Flow (this is covered in the Trailhead for flows), perhaps initiated from a Lightning Action that you add to the global ...


2

Yes you can put IP addresses in there as well. We've been doing this for years. Do note that salesforce does a 1:1 comparison between the domain name used in the callout and the Remote Site Setting. So you will have to use the IP address in the callout as well (and not the literal domain name).


2

One approach would be to store the token and its expiration date in Platform Cache. In the batch execute method, you would check the token in the cache. If you need to get a new token, call your authentication method and store the token in cache.


2

You'll need to roll your own client that implements the oAuth authorization code flow with PKCE extension. As you found out, Named Credential won't help you. The common wisdom is that tokens should be stored in custom settings and/or custom metadata. The latter can be updated via the Metadata API. You will also need to store the code verifier until it's ...


2

With the introduction of chaining Queueable, and the ability to chain Queueable with callouts, we can daisy-chain multiple callouts efficiently without having to "guess" how many batches we need upfront from the Batchable interface. A simple implementation would look like: public class ChainedCallout implements Queueable, Database.AllowsCallouts { ...


1

Presumably, your test class is using Test.startTest() and Test.stopTest() to force your batch class to run synchronously. You then receive a CalloutException because the callouts that would in normal production use run asynchronously in a separate transaction are forced to run in the context of the current transaction - where you've either already run DML ...


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