Skip to main content Tableau Conference is happening now. Tune in to activate your data superpowers with Tableau and Agentforce. Watch live on SF+ for exclusive digital content, new product demos, and key insights for data and analytics lovers.
Mathis Gory 님이 #Salesforce Developer에 질문했습니다

I'm using some named & external credentials in order to connect multiple systems in Salesforce.

 

I was wondering what was the best practice to make API calls to external systems.

 

Until now, I was using Apex Class and call this apex class from a flow, but I discovered "HTTP Callout" in flow which is amazing because you don't need to update an apex class to edit your logic.

 

My question is, it is a good practice to make API calls from "HTTP Callout" in flow ? Because i saw that it's taking resources from your daily limits and my flow is running each time an inbound email is incoming (so the HTTP Callout or Apex Class too)

 

Thanks in advance

답변 1개
  1. 2023년 12월 11일 오전 5:09

    Hi @Mathis Gory

    Hope you are doing well.

    You've brought up a great question about using HTTP callout in flows vs. Apex classes for making API calls to external systems in Salesforce. Both options have advantages and disadvantages, and the best choice depends on your specific needs and use case.

    Here's a breakdown of each option:

    Apex Class:

    Advantages:

     

    • More powerful and flexible: Apex classes can handle more complex logic and error handling than HTTP callouts in flows.

    • Better performance: Apex classes can be more performant than HTTP callouts, especially for bulk operations.

    • Greater control: Apex classes offer more fine-grained control over the API callout, including headers, body content, and error handling.

    • Reusable: Apex classes are reusable across different flows and processes.

     

    Disadvantages:

     

    • Requires development and testing: Implementing an Apex class requires coding and testing, which can be time-consuming.

    • Less user-friendly: Developers need to write and maintain the Apex code, which can be intimidating for non-technical users.

    • More resource intensive: Apex classes occupy Salesforce governor limits like CPU time and heap size.

     

    HTTP Callout in Flow:

    Advantages:

     

    • Easier to use: HTTP callouts can be configured directly within the flow builder, making them readily accessible to users without coding experience.

    • No development required: You don't need to write and maintain Apex code, saving time and resources.

    • Flexible configuration: Flows offer various triggers and conditions for executing the HTTP callout, allowing for diverse use cases.

    • Visual representation: Flows provide a visual representation of the logic, making them easier to understand and maintain.

     

    Disadvantages:

     

    • Limited functionality: HTTP callouts have less functionality than Apex classes, making them unsuitable for complex logic and error handling.

    • Performance concerns: HTTP callouts can be less performant than Apex classes, especially for bulk operations.

    • Resource consumption: Each HTTP callout in a flow counts towards your daily limits, which can be a concern for high-volume flows.

    • Limited control: You have less control over the API callout compared to Apex classes, such as limited customization of headers and body content.

     

    Considering your specific situation:

    Since your flow runs for every incoming email and potentially makes many HTTP callouts, resource consumption becomes a major concern. HTTP callouts in flows can quickly eat up your daily limits, impacting performance and potentially causing errors.

    Here's what I recommend:

     

    • For simple API calls without complex logic: Consider using HTTP callouts in flows for their ease of use and configuration.

    • For complex logic, error handling, or performance-critical calls: Use Apex classes for greater control, flexibility, and performance.

    • For high-volume operations: Evaluate the resource consumption of HTTP callouts and consider batching operations or using Apex classes for better efficiency.

    • Use named credentials: Always use named credentials instead of embedded credentials for improved security and compliance.

    • Monitor governor limits: Keep an eye on your governor limits to ensure your flows and Apex code don't exceed them.

     

    Ultimately, the best practice depends on your specific needs and the complexity of your API integration. Weigh the advantages and disadvantages of each option carefully and choose the one that best suits your requirements.

    Remember, you can always combine both approaches. You can use Apex classes for complex logic and call them from your flows using HTTP callouts. This way, you can leverage the benefits of both options for an efficient and secure integration.

     

    Hope this content will provide you more understanding on your ques(doubt)

    Thanks!

0/9000