Building a Weather Integration in Salesforce using Visualforce, Apex Callouts, Named Credentials, and Wrapper Classes
This guide walks through building a weather lookup app in Salesforce using Visualforce, Apex callouts, Named Credentials, Custom Metadata, and Wrapper Classes. It covers secure API integration without hardcoding endpoints or keys, and clean JSON response handling via wrapper classes. The resulting Visualforce page allows users to enter a city and retrieve real-time weather data displayed with a responsive UI. The approach demonstrates solid best practices for external API integrations in Salesforce, making it a practical example for developers and architects wanting to build maintainable and scalable integrations.
- Use Named Credentials to manage external API endpoints securely.
- Store API keys in Custom Metadata for easier configuration updates.
- Create Wrapper Classes for clean JSON response deserialization.
- Implement error handling via ApexPages messages for better UX.
- Use Visualforce and Apex to build interactive external data integrations.
External integrations are one of the most common requirements in Salesforce applications. In this article, we will build a Weather Information Viewer using Salesforce technologies such as Visualforce, Apex, Named Credentials, Custom Metadata, and Wrapper Classes. This project demonstrates how Salesforce can interact with external APIs and display real-time data inside a Salesforce UI. By the end of this guide, you will have a responsive Visualforce weather dashboard where a user can enter a city name and retrieve current weather information. Table of Contents What We Are Building We will build a weather lookup application that allows users to: Enter a city name Click the Get Weather button Fetch real-time weather data from an external API Display weather details in a clean Visualforce interface The weather data is fetched from: https://api.weatherapi.com/v1/current.json Example API request: https://api.weatherapi.com/v1/current.