Demographic Detail is very important for the business to validate the information and take the key decision for the customer. It will help businesses in better customer retention and reliability. Businesses can use this information to approve loans, insurance or lead management. This post will use Trestle Reverse Phone API to validate phone numbers and provide customer’s demographic information like age, phone network and type information, current and old address, all phone numbers and family member’s detail.
For this post, I have integrated API using Apex and shown demographic detail in Salesforce Screen Flow. I have also used unofficialsf datatable to show apex runtime data in tabular format. Let us see step-by-step guide to integrating Trestle Reverse Phone API.
- Get Trestle Reverse Phone API Access
- Create Named Credential and External Credential for API
- Create an apex class to integrate API
- Create Flow to show demographic detail
- Test Functionality in Salesforce Flow
1. Get Trestle Reverse Phone API Access
Trestle Reverse Phone API will provide all demographic information. This API is not free and we need access to use this API. You can check with their team to give access to this API. To get access first create a user in Developer Portal. Once the account is verified, Log into the developer portal and create an application for your usage. It will create an API key but API access is yet not provided. To get API access, we have to request it in the API section of the same page.
By default, access is not provided for this API. It might take 2-3 days for API access. Once it is approved, we can start integrating it.
2. Create Named Credential and External Credential for API
Let us create an external credential and named credential for the above API. Named Credential helps us to make maintainable code, no hardcoding is required.
Create an External Credential
Create an external credential Trestle API EC for authentication configuration.
|Label||Trestle API EC|
Create a Named Credential
Create a named credential Trestle API NC for Trestle API.
|Label||Trestle API NC|
|Authentication||Trestle API EC|
|Generate Authorization Header||Checked|
3. Create an apex class to integrate API
We are now ready to create an apex class that will integrate Trestle Reverse Phone API. I have used the External Callout class that is created in the post Generic Apex class for Calling External System. Check that post and create ExternalCallout class.
Below classes are created to accomplish our Salesforce Trestle Integration
- TrestleiqResponseWrapper – This is a wrapper class for API response.
- TrestleCalloutService – This apex class will call Trestle Reverse Phone API.
- DemographicDetailInvocable – This is an Invocable class that will be called from the flow.
As we need to use the API key provided by Trestle, we can use Custom Setting or Custom Metadata Type to store it. I have created one Hierarchy Custom Setting Trestle Access(TrestleAccess__c). You can create it based on your requirement. This custom setting has one field API Key (APIKey__c) to store API Key information. If you are changing the name or type of custom setting, change the code to access this custom setting in TrestleCalloutService apex class.
Complete Apex Code
4. Create a Flow to show demographic detail
Create a flow to show demographic detail for a given mobile number. API is returning the below details
- Person Full Name
- Person Age Group
- Person Phone Carrier
- Phone Type (Prepaid/PostPaid)
- Associated Phones
- Current and Old address
- Associated Family Details
Based on your requirement show the customer/client’s details. I have used flow to visualize these details but you can also use Lightning components.
Elements on Screen Flow
- Screen Element to Enter Mobile Number
- Apex Action to call API for a given Mobile Number
- Screen Element to show Demographic details
1. Screen Element to Enter Mobile Number
Add screen element and put text input element to enter mobile number.
2. Apex Action to call API for a given Mobile Number
Call above created Apex Action ‘Get Demographic Detail’ created in apex class DemographicDetailInvocable. This action is returning all above mentioned information. For this post, I have shown all detail on a screen so create multiple variables to store this information. All those variables are of text type.
3. Screen Element to show Demographic details
Add a screen element to show data on the screen. I have used unofficialsf datatable to show data in tabular format. Standard Flow Data Table is right now not supporting showing data from the Apex Wrapper class so use this package. You can display information in the Display element.
Let me provide the configuration for one of the datatable for showing data from the Apex data wrapper.
Add Datatable from the custom section of the flow element on the screen component. By default, it will ask to select an object to show data. Let us set the properties of unofficialsf data table for apex wrapper.
- Check property Input data is Apex-Defined from the advanced section. It will enable the Datatable Record String property in Data Source section
- In Column Fields of the Advance section, set field names as comma-separate lists. Example – StreetLine1,StreetLine1,City,State,PostalCode for address
- In Column Types (Col#:type,…) set 1:text,2:text,3:text,4:text,5:text
- Key Field – set key field
Using the above properties it will show data in a table. You can also set up other elements like this.
Below is the flow element configuration screenshot for easy understanding.
5. Test Page
As this post is related to demographic information, I can not show complete information about any phone/mobile number. Just showing an image for the response.
Note – This API will only show data for USA mobile numbers.
Other Related Posts
Other Integration Posts
Need some kind of help in implementing this feature, connect on my LinkedIn profile Dhanik Lal Sahni.