Overview
Web service flow in Salesforce describes how Salesforce interacts with external systems (and vice versa) using web services. This includes exposing Salesforce functionality via SOAP/REST endpoints, consuming external APIs through Apex callouts, and using platform features like Outbound Messaging, Platform Events, and Named Credentials to manage integration and authentication.
Key Components
Understanding the web service flow means knowing the following components:
- APIs & Protocols: SOAP and REST are the primary protocols. Use SOAP for strict contracts (WSDL) and REST for lightweight, resource-based calls.
- Apex Web Services: Create SOAP web services with webService methods (Apex SOAP) or REST endpoints with @RestResource and HTTP method annotations.
- Apex Callouts: Salesforce as a client calling external services (HTTP, SOAP). Use HttpRequest/Http classes or generated Apex from WSDL.
- Authentication: OAuth 2.0, Named Credentials, certificate-based auth, or basic auth. Named Credentials significantly simplify auth and endpoint management.
- Asynchronous Patterns: Future methods, Queueable Apex, Platform Events, and Batch processes to handle long-running or retryable integrations.
- Governors & Limits: Limits on callouts (100 callouts per transaction, cumulative timeout ~120s), heap size, and CPU time must be considered.
Typical Web Service Flows
1) Inbound SOAP Web Service (External system -> Salesforce)
Flow: External SOAP client calls Salesforce WSDL endpoint -> Salesforce executes the Apex webService method -> Salesforce returns SOAP response.
Implementation notes:
- Define a global Apex class with webService methods.
- Generate and share the WSDL (Setup > Apex Classes > WSDL).
- Handle authentication (username/password with session ID, or use a middleware that handles OAuth).
global class AccountService {
webService static Id createAccount(String name) {
Account a = new Account(Name = name);
insert a;
return a.Id;
}
}
2) Inbound REST Web Service (External system -> Salesforce)
Flow: External system sends HTTP request to a Salesforce REST endpoint -> Salesforce maps request via @RestResource -> executes Apex logic -> returns JSON/XML response.
@RestResource(urlMapping='/orders/*')
global with sharing class OrderApi {
@HttpPost
global static String createOrder(String body) {
// parse JSON, create records, return response
return 'OK';
}
}
3) Outbound Callout (Salesforce -> External system)
Flow: Apex code prepares an HTTP request -> authenticates (Named Credential / OAuth) -> sends request -> handles response synchronously or asynchronously.
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:My_Named_Credential/api/v1/resource');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
String body = res.getBody();
Design & Implementation Steps
- Define integration requirements (payloads, throughput, security, SLA).
- Choose protocol (SOAP vs REST) and authentication mechanism.
- Design data mapping and error handling (retries, dead-letter queue using Platform Events or Queueable Apex).
- Implement endpoints or callouts using Apex, Named Credentials, or Declarative features (Outbound Messaging).
- Secure endpoints (IP restrictions, OAuth scopes, TLS, certificate pinning if required).
- Test thoroughly: unit tests, integration tests (mock callouts with HttpCalloutMock), and load tests.
Best Practices
- Use Named Credentials to manage endpoints and authentication centrally.
- Prefer asynchronous processing for long-running integrations (Queueable, Platform Events).
- Use HttpCalloutMock in tests to avoid external dependencies and to achieve coverage.
- Handle partial failures and implement idempotency where possible.
- Monitor integrations with debug logs, Event Monitoring, and Connected App usage.
Common Interview Tips
When asked about web service flow in Salesforce, describe both directions (inbound and outbound), mention authentication patterns, and highlight governor limits and testing strategy. Give a short code example (SOAP or REST) and explain when you would use Named Credentials or Platform Events.
Summary
Web service flow in Salesforce covers how data and actions move between Salesforce and external systems using SOAP/REST endpoints, Apex callouts, and platform features. The key is to design secure, scalable, and testable integrations while respecting Salesforce governor limits.






Leave a Reply