All Projects → jongpie → ApexCallouts

jongpie / ApexCallouts

Licence: MIT license
A lightweight Apex library for making HTTP callouts. Works with remote site settings and named credentials.

Programming Languages

Apex
172 projects

Projects that are alternatives of or similar to ApexCallouts

sfdc-error-playground
Lightning & Apex Error Playground
Stars: ✭ 30 (-6.25%)
Mutual labels:  salesforce, apex
apex-rest-route
A simple framework for building Restful API on Salesforce
Stars: ✭ 75 (+134.38%)
Mutual labels:  salesforce, apex
Dreamhouse Sfdx
Salesforce Sample App part of the sample gallery. Real estate use case. Get inspired and learn best practices.
Stars: ✭ 164 (+412.5%)
Mutual labels:  salesforce, apex
Dreamhouse Lwc
Sample application for Lightning Web Components on Salesforce Platform. Part of the sample gallery. Real estate use case. Get inspired and learn best practices.
Stars: ✭ 136 (+325%)
Mutual labels:  salesforce, apex
apex-mocks-stress-test
Testing out FFLib versus Crud / CrudMock
Stars: ✭ 47 (+46.88%)
Mutual labels:  salesforce, apex
Prettier Plugin Apex
Code formatter for the Apex Programming Language
Stars: ✭ 138 (+331.25%)
Mutual labels:  salesforce, apex
codeclimate-apexmetrics
ApexMetrics - Code Climate engine for Salesforce [DISCONTINUED use CC PMD instead)
Stars: ✭ 46 (+43.75%)
Mutual labels:  salesforce, apex
Vim Force.com
Vim plugin for force.com
Stars: ✭ 98 (+206.25%)
Mutual labels:  salesforce, apex
timeline-component-lwc
This component enables timeline view for Salesforce Record history.
Stars: ✭ 18 (-43.75%)
Mutual labels:  salesforce, apex
Sfdx Mass Action Scheduler
🚀 Declaratively schedule Process Builder, Flows, Quick Actions, Email Alerts, Workflow Rules, or Apex to process records from Reports, List Views, SOQL, or Apex.
Stars: ✭ 200 (+525%)
Mutual labels:  salesforce, apex
Visualforce Table Grid
Flexible and highly customizable Visualforce table grid component. Salesforce.com Classic Look and Feel.
Stars: ✭ 126 (+293.75%)
Mutual labels:  salesforce, apex
universalmock
A universal mock class in Apex
Stars: ✭ 55 (+71.88%)
Mutual labels:  salesforce, apex
Testdatafactory
The ultimate Apex Test Data Factory 🏭
Stars: ✭ 108 (+237.5%)
Mutual labels:  salesforce, apex
apex-rollup
Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.
Stars: ✭ 133 (+315.63%)
Mutual labels:  salesforce, apex
Easy Spaces Lwc
Sample application for Lightning Web Components on Salesforce Platform. Part of the sample gallery. Event management use case. Get inspired and learn best practices.
Stars: ✭ 104 (+225%)
Mutual labels:  salesforce, apex
Apex Lambda
Functional programming for Salesforce Apex
Stars: ✭ 189 (+490.63%)
Mutual labels:  salesforce, apex
Apextestkit
A way to simplify your Salesforce data creation.
Stars: ✭ 80 (+150%)
Mutual labels:  salesforce, apex
Awesome Low Code
Awesome Low-Code Application Platforms | 全球低代码平台开发资源大全
Stars: ✭ 90 (+181.25%)
Mutual labels:  salesforce, apex
Haoide
Stop upgrade, most of features were delivered in https://github.com/xjsender/haoide-vscode
Stars: ✭ 194 (+506.25%)
Mutual labels:  salesforce, apex
Soqlx
SoqlXplorer is an awesome tool for developers using the Salesforce.com platform.
Stars: ✭ 220 (+587.5%)
Mutual labels:  salesforce, apex

Apex Callouts

A lightweight Apex library for making HTTP callouts
Deploy to Salesforce

Using Callout Constructors

  • Callout(String endpoint) - used when you have a full URL for the endpoint and you are using remote site settings
  • Callout(String namedCredential, String endpointPath) - used with named credentials. To use this, the named credential's endpoint should be just the base URL of the API. The specific endpoint resource to call is then provided via the endpointPath parameter.

Building Your Callout Request

Once you have instantiated an instance of Callout, you can setup additional options for the callout, like adding headers & parameters. Each builder method returns the current instance of Callout, allowing you to chain the builder methods.

  • Callout setClientCertificateName(String clientCertificateName)
  • Callout setCompressed()
  • Callout setCompressed(Boolean compress)
  • Callout setHeader(String key, String value)
  • Callout setHeaders(Map<String, String> headers)
  • Callout setParameter(String key, String value)
  • Callout setParameters(Map<String, String> parameters)
  • Callout setTimeout(Integer timeoutMs)

Making Your Callout Request

Once you have instantiated an instance of Callout and setup the headers & parameters (if needed), you can call any of the HTTP verb methods - each method returns an instance of HttpResponse.

  • HttpResponse del() - 'delete' is a reserved word in Apex, so the method name has been abbreviated
  • HttpResponse get()
  • HttpResponse head()
  • HttpResponse patch() or patch(Object requestBody)
  • HttpResponse post() or post(Object requestBody)
  • HttpResponse put() or put(Object requestBody)
  • HttpResponse trace()

PATCH, POST & PUT methods

Patch, post & put methods accept an Object as a parameter, with 3 main types supported

  • Blob: Callout automatically uses setBodyAsBlob(yourBlob)
  • Dom.Document: Callout automatically uses setBodyDocument(yourDocument)
  • Serializable Object: Any other object types will be serialized and sent as JSON, using setBody(JSON.serialize(yourObject))

For all 3 scenarios, the header 'Content-Type' is automatically set based on the request body if the header has not already been set

Error Handling

When the callout is made, any status code >= 400 automatically throws an instance of Callout.HttpResponseException exception

Example Usage

GET request with headers & parameters, using chained method calls & named credentials

HttpResponse myCalloutResponse = new Callout('myExampleNamedCredential', '/fakeResource')
    .addHeader('myHeader', 'myHeaderValue')
    .addParameter('myFirstParameter', 'someValue')
    .addParameter('mySecondParameter', 'anotherValue')
    .get();

GET request with headers & parameters, using chained method calls & a full URL (remote site settings)

HttpResponse myCalloutResponse = new Callout('https://api.example.com/fakeResource')
    .addHeader('myHeader', 'myHeaderValue')
    .addParameter('myFirstParameter', 'someValue')
    .addParameter('mySecondParameter', 'anotherValue')
    .get();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].