3

For webservice callouts, I assume the same rules apply, but I just wanted to double check. I haven't found any information about Platform Events and Webservices. I assume I would just make it a @future method to avoid erroring out?

1

Just to clarify: The question appears to be "CAN" you do it, not "SHOULD" you do it.

So the answer is YES, you can execute a callout from a trigger on the Platform Event object, much like you could when you, say, insert an Account.

I refuse to comment on whether or not you SHOULD do it - there are experts in architecture here who are much smarter than I am. :)

3

Yes, Even I was wondering with the same kind of questions when I first heard about platform event in Salesforce.

But after taking up Platform Event Trailhead Module, All of my doubts got cleared And here are some major takeaway from the same :

  1. Platform events are like other salesforce records(but can't be edited or deleted.)
  2. You can perform only after insert(in triggers).
  3. After you (publisher) create a platform event, consumer(subscriber) can listen to it.

But i don't think that you would make a web service callout after creating a platform event(just ponder over this use case again and you will know that this is not proper use case for platform events, because when you are creating a platform event, your subscribers which are connected to event channel is already polling/listening for this event).

But still, if you are curious to try out, Because platform events are published by inserting the event sObjects, standard API request limits apply. Referencing a link for further help.

Considerations for Publishing and Subscribing to Platform Events with Apex and API

  • I am not sure what you mean by: because when you are creating a platform event, your subscribers which are connected to event channel is already polling/listening for this event). can you explain this again? – Olivia Mar 5 '18 at 16:48
  • "our subscribers which are connected to event channel is already polling/listening for this event" ---- Unless you have code in a Community or LtngOut that you want to notify. That code can't listen for platform events. – Andy Visser Sep 27 '19 at 14:29
3

Older question but felt compelled to add an answer, as I was confused by what was presented here so far.

If you are asking "can I make an Apex HTTP Callout from my Apex Platform Event Trigger?" then the answer is NO.

System.CalloutException: Callout from triggers are currently not supported.

Here's John Brock, the product owner for Platform Events, in the Platform Events success community chatter group March 7, 2019:

Longer term we also hope to relax some of the limits and restrictions on Platform Event triggers since they are executed asynchronously -- such as, I would love to be able to do callouts directly from Apex Triggers.

What you can do, and I think the OP alluded to this when mentioning @future, is to call an asynchronous context like @future or Queueable from your trigger, and do the HTTP Callout from that context instead.

2

The event driven architecture approach is subscribing to the platform event in the external service instead of calling a external service - but this only works if you are in control of the service you wan't to call

  • Interesting. What would be the drawback to calling it in the trigger? why would it be better to call it in the service? – Olivia Mar 4 '18 at 20:31
  • @olivia not calling it "in" the service but implementing a service "subscribing" to this event - if you are interested i can post a few links to get into event driven architecture and unified log – pelim Mar 4 '18 at 21:21
0

I found this blog: https://developer.salesforce.com/blogs/developer-relations/2017/05/first-impressions-platform-events-salesforce-enterprise-messaging-platform.html

One of the items they hit on is the point of the Platform Events. He says:

The vision for Platform Events is simple: Empower our customers to increase business productivity and efficiency through integrations via events. We want to enable customers to create more integrations between Salesforce and their systems. Using Platform Events, customers can support more interaction between Salesforce and their data. The goal is to reduce the number of point-to-point integrations and expand on the existing capabilities of our other integration options such as Outbound Messaging, Apex Callouts, and the Streaming API.

I interpret this as a green light to connect the two. If anyone has any thoughts on this feel free to comment.

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.