This repository contains the implementation of a Salesforce solution to integrate country data using the CountryLayer API and manage lead information based on country details. The project includes the following key components:
API Integration: The CountryService class fetches country information from the CountryLayer API (using a Named Credential), including fields such as Name, Alpha2Code, Alpha3Code, Capital City, Region, and RegionalBlocs. Daily Update: A Schedulable class (CountryServiceScheduler) ensures country data is updated daily. Any changes in the API are reflected in Salesforce. Test Class: CountryServiceTest mocks the API response and verifies both the insert and update logic for country records.
A lead trigger (LeadTrigger) automatically populates lead records with country-related data based on the lead's country. The LeadHandler class fetches the country data from Salesforce and fills in fields like Alpha2Code, Alpha3Code, Capital City, Region, and RegionalBlocs. Test coverage is provided in LeadHandlerTest.
A validation rule (PreventOwnerChange) ensures that the Lead Source, Country, and Number of Employees fields must be filled in before the Lead Owner can be changed. Exceptions are made for specific profiles (System Administrator and Contract Manager).
A flow tracks and records the timestamp when a Lead Owner is assigned, storing the date in the Owner Since field.
All metadata, including custom objects, validation rules, triggers, and classes, are ready for deployment and can be found in the repository.
The solution includes comprehensive unit tests for API callouts, triggers, and validation rules, ensuring the system is fully testable and ready for deployment.