Welcome to the Weather Forecast LWC Project! This Salesforce Lightning Web Component (LWC) app connects to the OpenWeather API to bring you real-time weather updates. The app lets you:
- Fetch a 5-day weather forecast by entering a city name 🌆.
- Automatically fetch weather data based on the Billing City of an Account record 🏢.
-
City-Based Weather Forecast 🌇:
- Enter a city name to get a 5-day weather forecast.
- Displays temperature, date, and weather conditions in a user-friendly table.
-
Billing City-Based Weather Forecast 🏙️:
- Automatically fetches weather data for the Billing City of an
Account
record. - Perfect for Account-specific insights! 🗺️
- Automatically fetches weather data for the Billing City of an
-
Reusable Weather Table 🔄:
- A reusable LWC component that can be used across different parts of your app to display weather data.
-
City-Based Forecast 🌇:
- Go to the page with
searchWeather
and enter a city name. - Click Search to display the 5-day forecast in a table.
- Go to the page with
-
Billing City Forecast 🏙️:
- Go to an
Account
record that has theBilling City
filled. - The
weatherForecastByBillingCity
component will automatically show the weather for the Billing City.
- Go to an
Weather-Forecast-LWC/
├── force-app/
│ └── main/
│ └── default/
│ ├── aura/
│ ├── classes/
│ │ └── WeatherForecastController.cls
│ ├── lwc/
│ │ ├── SearchWeatherForecoast/
│ │ ├── ForecastByBillingCity/
│ │ └── WeatherTableForecast/
│ └── layouts/
├── .gitignore
├── README.md
└── images/
├── SearchWeather.png
└── BillingCity.png
- Salesforce Developer Org or Sandbox (Make sure you have API access enabled).
- Salesforce CLI installed.
- OpenWeather API Key (Sign up here to get one).
git clone https://github.com/KislayKashyap-hub/Weather-Forecast-LWC.git
cd Weather-Forecast-LWC
sfdx force:source:deploy -p force-app
Go to Setup → Remote Site Settings → New Remote Site and add:
- Name:
OpenWeatherAPI
- URL:
https://api.openweathermap.org
Replace YOUR_API_KEY
in the WeatherController
Apex class with your actual OpenWeather API key:
String endpoint = 'https://api.openweathermap.org/data/2.5/forecast?q=' + cityName + '&appid=YOUR_API_KEY&units=metric';
- Search Weather Component: Add
searchWeather
to any Lightning App Page. - Billing City Weather Component: Add
weatherForecastByBillingCity
to anAccount
Lightning Record Page.
- Error Handling: Add better handling for incorrect city names or empty
BillingCity
. - Secure the API Key: Use Salesforce Custom Metadata or Custom Settings for storing the API key securely.
- UI Enhancements: Display more weather details like wind speed, humidity, etc.
- Test Classes: Improve the test coverage for Apex code to ensure reliability.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Feel free to fork the repository, create a new branch, and submit a pull request.
You can reach out to me on the following platforms:
- 📧 Email: [email protected]
- 🌐 LinkedIn: Kislay Kumar
- 🔗 Trailhead: Kislay Kumar on Trailhead
Let’s stay connected and keep building amazing projects together! 🚀