Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Get Request entry
How-to guide

Make a GET callout from Apex

Setting up a GET callout takes three Apex statements once the Named Credential is in place. The rest is parsing the response.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated May 21, 2026

Setting up a GET callout takes three Apex statements once the Named Credential is in place. The rest is parsing the response.

  1. Create a Named Credential

    Setup, Named Credentials, New. Enter the URL, choose the authentication protocol, and save. The Named Credential gets a unique name (e.g., StripeApi).

  2. Build the HttpRequest in Apex

    HttpRequest req = new HttpRequest(); req.setEndpoint('callout:StripeApi/customers/cus_abc'); req.setMethod('GET'); The callout: protocol references the Named Credential and injects authentication automatically.

  3. Send and capture the response

    Http http = new Http(); HttpResponse res = http.send(req); String body = res.getBody(); Integer status = res.getStatusCode();

  4. Parse the JSON

    Use JSON.deserialize or JSON.deserializeUntyped to convert the body into an Apex object or a Map. Handle missing fields and null values explicitly.

  5. Handle errors and retry transient failures

    Check status code; 2xx is success, 4xx is a client error (do not retry), 5xx is a server error (retry with backoff). Log failures to a custom Object or a logging framework.

Mandatory fields
Endpointrequired

The URL or Named Credential reference the request targets.

Methodrequired

GET; setMethod is optional but should be explicit.

Authenticationrequired

Handled by Named Credential or set explicitly with setHeader('Authorization', 'Bearer ...').

Timeoutrequired

Defaults to 10 seconds; max 120. Set via setTimeout(120000) for slow endpoints.

Gotchas
  • Apex callouts cannot be made after a DML statement in the same transaction. Make the GET first or move the DML to an async context.
  • Hard-coding endpoint URLs in Apex breaks across sandbox, production, and packaged deployments. Use Named Credentials instead.
  • The 6-MB response limit is hard. APIs returning large payloads must paginate; the Apex code must follow the next-page links.
  • Query-string parameters with special characters need EncodingUtil.urlEncode. Skipping the encode leads to silent integration failures when users have apostrophes or spaces in input.

See the full Get Request entry

Get Request includes the definition, worked example, deep dive, related terms, and a quiz.