The following JavaScript code will check if the current Salesforce user signed into the Formyoula mobile app is active on Salesforce. If the user is deactivated, the mobile application will sign out the logged-in user.
Please add below JavaScript code on your Formyoula form deployed to your users.
Please copy the code and paste it into “JavaScript Code (Form Edit Page)”.
( function() {
// Check if JavaScript already loaded
if ( !window[ 'formyoula_set_interval_check_if_user_is_active_on_salesforce' ] ) {
// Start Interval
window[ 'formyoula_set_interval_check_if_user_is_active_on_salesforce' ] = setInterval( function() {
// Check if Formyoula user has a Salesforce Id
if ( window.formyoula.user && window.formyoula.user.Formyoula_User_Salesforce_Id ) {
// Run main check function
check_if_salesforce_user_is_active();
}
}, 1000 * 60 * 5 ); // END Interval
// Function for checking active user
function check_if_salesforce_user_is_active() {
// Query for logged-in User
formyoula.sfdc.query(
'Select Id, IsActive from User Where Id=\'' + window.formyoula.user.Formyoula_User_Salesforce_Id + '\'',
function() {},
function( error ) {
// Check if error has the inactive description
if ( error && error.responseJSON && error.responseJSON.error_description == 'inactive user' ) {
// Trigger signout
window.formyoula.event_trigger( 'sync:clear_all', {} );
window.formyoula.event_trigger( 'login:main', {} );
// Remove user details
delete window.formyoula.user;
}
}
);
}
}
} )();
For any questions, please contact us - [email protected] or the Formyoula in-app chat 🙂