A comprehensive Salesforce integration with the Sana Learn API for analytics reporting and user completion tracking. This solution provides real-time learning analytics data within Salesforce's reporting and dashboard ecosystem.
SanaLearnAuthSettings__mdt: Custom metadata type storing API credentials (client ID, secret, tenant info)- Token Management: Automatic OAuth token retrieval and refresh using Sana's authentication endpoints
- Secure Storage: API credentials stored in custom metadata for easy configuration without code changes
- Retrieves OAuth tokens using stored client credentials
- Handles token refresh automatically when tokens expire
- Supports multiple environments through metadata configuration
- Breakdown of course completions by course type
- Shows distribution across different learning content types
- Useful for understanding which content formats are most popular
- Individual user completion data with:
- User Display Names → parsed into First Name and Last Name
- Email addresses
- Course completion counts
- Sana User IDs
- Last sync timestamps
SanaInsightsController.cls: Main API integration class handling all analytics types- Easy to add new analytics endpoints by extending the existing pattern
- Standardized error handling and data processing
- Job Creation: POST request to Sana API creates analytics job
- Polling System: Monitors job status with configurable intervals
- Data Retrieval: Downloads CSV results when job completes
- Data Filtering: Removes test users and invalid data automatically
- 24-Hour Caching:
SanaAnalyticsCache__ccustom object prevents unnecessary API calls - Smart Polling: Configurable delays and retry limits to respect API limits
- Batch Processing: Handles large datasets efficiently
sanaDashboardSync: Manual sync interface with progress tracking- Real-time Status: Shows last sync information and relative timestamps
- User-Friendly Interface: Toast notifications and loading states
- Custom Object Storage:
Sana_User_Completion__cstores all user completion data - Standard Reports: "Top Course Completers" report with sortable columns
- Dashboard Components: Bar charts, tables, pie charts showing completion metrics
- Folder Organization: Dedicated "Sana Reports" and "Sana Dashboards" folders
- Lightning Pages: "Sana Analytics" page for easy access
- App Launcher: Searchable components accessible from anywhere
- Navigation Integration: Can be added to app navigation menus
- Upsert Logic: Uses
Sana_User_ID__cas external ID to prevent duplicates - Name Parsing: Automatically splits display names into first/last name fields
- Test Data Filtering: Removes Sana test accounts and invalid entries
- Timestamp Tracking: Records when each sync occurred
- Comprehensive Logging: Debug information for troubleshooting
- Graceful Degradation: System continues working even if individual records fail
- User Feedback: Clear error messages displayed in UI
| Class | Purpose |
|---|---|
SanaInsightsController |
Main API integration and analytics job management |
SanaDashboardDataSync |
User completion data synchronization logic |
SanaConnectionTestLWC |
API connectivity testing and validation |
| Object | Purpose |
|---|---|
Sana_User_Completion__c |
Stores individual user completion data |
SanaAnalyticsCache__c |
24-hour caching for API responses |
SanaLearnAuthSettings__mdt |
API authentication configuration |
| Component | Purpose |
|---|---|
sanaDashboardSync |
Manual data synchronization interface |
sanaConnectionTestLWC |
API connection testing tool |
- Real-time Visibility: See course completion progress across organization
- Performance Metrics: Identify top learners and completion trends
- Reporting Flexibility: Use standard Salesforce reporting tools
- Low Maintenance: Caching reduces API usage and improves performance
- Scalable Architecture: Can handle growing user bases and data volumes
- Secure Integration: Uses Salesforce security model and encrypted credentials
- Salesforce Org with Lightning Experience enabled
- Sana Learn API Access with valid credentials
- Admin Permissions to deploy custom objects and classes
-
Deploy Metadata:
sf project deploy start --source-dir force-app/
-
Configure API Credentials:
- Navigate to Setup → Custom Metadata Types → Sana Learn Auth Settings
- Create new record with your Sana API credentials
-
Setup Remote Site Settings:
- Add your Sana API endpoint to Remote Site Settings
- Enable secure connections
-
Assign Permissions:
- Grant users access to custom objects and Lightning components
- Configure Lightning App with Sana Analytics page
| Setting | Location | Purpose |
|---|---|---|
| API Credentials | Custom Metadata | Sana Learn authentication |
| Remote Sites | Setup → Remote Site Settings | Allow API calls to Sana |
| Page Assignments | Lightning App Builder | Add components to pages |
-
Access Sync Interface:
- App Launcher → Search "Sana Analytics"
- Click "Sync Data" button
-
Monitor Progress:
- Watch for success/error toast notifications
- Check "Last Sync" information for status
-
Access Reports:
- App Launcher → "Reports"
- Navigate to "Sana Reports" folder
- Open "Top Course Completers" report
-
Create Dashboards:
- Reports tab → Dashboards
- Click "New Dashboard" → "Classic Dashboard"
- Add components using Sana reports
| Endpoint | Purpose | Frequency |
|---|---|---|
/api/analytics/course_type_analytics |
Course type breakdown | On-demand |
/api/analytics/user_completions_analytics |
User completion data | Daily recommended |
/oauth/token |
Authentication token refresh | As needed |
- Sync Status: Last successful sync timestamp
- Error Logging: Debug logs for API calls and data processing
- Cache Status: 24-hour cache hit/miss tracking
| Issue | Cause | Solution |
|---|---|---|
| "No valid data points" | API returns job status instead of CSV | Check job polling logic |
| Authentication errors | Expired tokens or invalid credentials | Verify metadata configuration |
| Empty reports | No data synced yet | Run manual sync first |
| Slow performance | API rate limiting | Enable caching, reduce sync frequency |
- Developer Console: Check Apex debug logs
- Setup → Jobs: Monitor async operations
- Custom Objects: Verify data population in
Sana_User_Completion__c
- Automated Scheduling: Salesforce scheduled jobs for regular syncing
- Advanced Filtering: Additional user and course filtering options
- Mobile Support: Responsive design for mobile devices
- Additional Analytics: More Sana analytics endpoint integrations
The codebase is designed for easy extension:
- New Analytics Types: Add to
SanaInsightsController.fetchAnalyticsResult() - Custom Fields: Extend
Sana_User_Completion__cobject - UI Components: Create additional Lightning Web Components
- Reporting: Build custom reports and dashboards
- Salesforce Trailhead: Lightning Platform development
- Sana API Documentation: Official API reference
- Apex Developer Guide: Salesforce development best practices
- Check Debug Logs: Enable debug logging in Developer Console
- Verify Configuration: Ensure all metadata settings are correct
- Test API Connectivity: Use the built-in connection test component
- Review Error Messages: Check toast notifications and system logs
Version: 1.0
Last Updated: December 2024
Compatibility: Salesforce API v58.0+, Sana Learn API v2+