Salesforce Mobile Dev Part 2 – APEX Controller

Written by ShamrockCRM on July 27, 2012 – 1:08 pm



Yesterday, I posted the VisualForce code for developing a mobile “insert user” page.  Today, I am posting the details on the APEX Controller required to perform the heavy lifting in Salesforce.

This APEX Class will perform a few tasks: 1) It will query the available Roles, User License types, and Profiles for population into the dropdown select lists. 2) Perform an “insert” of the new user into the database. 3) Return the DML error message if an error occurred (e.g. username already exists, etc.).

Currently, this code is only enabled to work with the “Salesforce” User License type. This could be enhanced to allow for Force.com platform licenses, Chatter licenses, etc.

global with sharing class usermanagerController {

    @RemoteAction
    global static String insertUser(String firstName, String lastName, String email, String profile, String role, String sendEmail) {
        try {
            String alias = firstName.substring(0, 2) + lastName.substring(0, 2) + email.substring(0, 2);
            User u = new User(IsActive = true, FirstName = firstName, LastName = lastName, Email = email, Username = email, ProfileId = profile, UserRoleId = role, Alias = alias, DefaultGroupNotificationFrequency = 'D', DigestFrequency = 'D', EmailEncodingKey = 'ISO-8859-1', LanguageLocaleKey = 'en_US', LocaleSidKey = 'en_US', TimeZoneSidKey = 'America/Los_Angeles', UserPermissionsCallCenterAutoLogin = false, UserPermissionsMarketingUser = false, UserPermissionsOfflineUser = false);

            if (sendEmail == 'on') {
                Database.DMLOptions dlo = new Database.DMLOptions();
                dlo.EmailHeader.triggerUserEmail = true;
                u.setOptions(dlo);
            }
            insert u;
        } catch (DmlException e) {
            return e.getDmlMessage(0);
        }
        return 'true';
    }

    @RemoteAction
    global static List < Profile > queryProfile() {
        //Only works for SFDC, enable later for Force.com with a dependent picklists in jquery
        ID salesforceUserLicense = [Select Id from UserLicense where Name = 'Salesforce'
        limit 1].Id;
        String profileQuery = 'Select Id, Name, UserLicenseId From Profile where UserType = \'Standard\' And UserLicenseId = :salesforceUserLicense ORDER BY Name ASC';
        List < Profile > p = Database.query(profileQuery);
        return p;
    }

    @RemoteAction
    global static List < UserRole > queryRole() {
        String roleQuery = 'Select Id, Name From UserRole where PortalType = \'None\' ORDER BY Name ASC';
        List < UserRole > r = Database.query(roleQuery);
        return r;
    }

    @RemoteAction
    global static List < UserLicense > queryUserLicense() {
        String ulQuery = 'Select Id, Name, LicenseDefinitionKey From UserLicense where Name =\'Salesforce\' limit 1';
        List < UserLicense > ul = Database.query(ulQuery);
        return ul;
    }
}

Next, I will post details on the JavaScript.


Tags: , , , , , , ,
Posted in Force.com User Adoption, HTML5, Salesforce Mobile, Salesforce.com | No Comments »

Salesforce Mobile Development – Create New User Code

Written by ShamrockCRM on July 26, 2012 – 11:53 am



See below for code on how to implement a Create New User form in HTML5/VisualForce.

I recently released an HTML5/VisualForce Salesforce.com mobile application recently on the AppExchange for managing Salesforce.com adoption named Adoption Manager.  The purpose is to review users that have not logged in for long periods of time and quickly deactivate them.  It also allows the creation of new users, searching of users, and viewing inactive users.

Below is a screenshot of the Create New User form.  I will walk you through the code to implement something similar.

Salesforce.com mobile development new user

To build this, you need a VisualForce page, an APEX class, and a JavaScript component:

VisualForce:

<apex:page showHeader="false" docType="html-5.0" standardStylesheets="false" cache="true" controller="usermanagerController">
    <html>
        <head>
            <title>Adoption Manager</title>
            <link rel="stylesheet" href="{!URLFOR($Resource.usermanager_jQuery, 'jquery.mobile-1.0.1.min.css')}"/>
            <apex:includeScript value="{!URLFOR($Resource.usermanager_jQuery, 'jquery.min.js')}"/>
            <apex:includeScript value="{!URLFOR($Resource.usermanager_jQuery, 'jquery.mobile-1.0.1.min.js')}"/>
            <apex:includeScript value="{!URLFOR($Resource.usermanager)}"/>
            <apex:includeScript value="{!URLFOR($Resource.forcetk)}"/>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;"/>
        </head>
        <body>
            <div data-role="page" data-theme="d" id="newuserpage">
                <div data-role="header">
                    <h1>Create New</h1>
                </div>
                <div data-role="content">
                    <div class="content-primary">
                        <div id="errorMessageNewUserDiv">
                            <span style="color:red;" id="errorMessageNewUser"></span>
                        </div>
                        <div>
                            <span><strong>* All fields are required for user creation</strong></span><br/><br/></div>
                        <form action="javascript:alert('This user has been created');" id="newUserFormForm">
                            <div data-role="fieldcontain">
                                <label for="firstNameForm">First Name:</label>
                                <input type="text" name="firstNameForm" id="firstNameForm" value="" placeholder="First Name" data-mini="true" maxlength="40"/>
                            </div>
                            <div data-role="fieldcontain">
                                <label for="lastNameForm">Last Name:</label>
                                <input type="text" name="lastNameForm" id="lastNameForm" value="" placeholder="Last Name" data-mini="true" maxlength="80"/>
                            </div>
                            <div data-role="fieldcontain">
                                <label for="emailForm">Email (Username):</label>
                                <input type="email" name="emailForm" id="emailForm" value="" placeholder="Email@email.com" data-mini="true" maxlength="80"/>
                            </div>
                            <div data-role="fieldcontain">
                                <label for="userlicenseForm" class="select">User License:</label>
                                <select name="userlicenseForm" id="userlicenseForm" data-mini="true"></select>
                            </div>
                            <div data-role="fieldcontain">
                                <label for="profileForm" class="select">Profile:</label>
                                <select name="profileForm" id="profileForm" data-mini="true"></select>
                            </div>
                            <div data-role="fieldcontain">
                                <label for="roleForm" class="select">Role:</label>
                                <select name="roleForm" id="roleForm" data-mini="true"></select>
                            </div>
                            <div data-role="fieldcontain">
                                <label for="generatePassForm">Generate password and notify user?</label>
                                <select name="generatePassForm" id="generatePassForm" data-role="slider" data-mini="true">
                                    <option value="on">Yes</option>
                                    <option value="off">No</option>
                                </select>
                            </div>
                            <div class="ui-body ui-body-b">
                                <fieldset class="ui-grid-a">
                                    <div class="ui-block-b">
                                        <button type="submit" data-theme="d" data-mini="true">Create</button>
                                    </div>
                                </fieldset>
                            </div>
                        </form>
                    </div>
                </div>
                <div data-role="footer" data-id="foomain" data-position="fixed"></div>
            </div>
        </body>
    </html>
</apex:page>

Notice that the userLicense, Profile, Role dropdown fields are not populated. They will be dynamically populated with JavaScript and using a query in the APEX Controller. Also notice the use of JQuery mobile components (e.g. email form fields, etc.).

Next article will be the APEX controller.

*And let me apologize in advance if any of the code is not the prettiest at the moment. :)


Tags: , , , , , ,
Posted in Force.com User Adoption, HTML5, Salesforce Mobile, Salesforce.com, VisualForce | 1 Comment »

Adoption Manager – Free mobile adoption app

Written by ShamrockCRM on June 4, 2012 – 8:08 pm

As a bit of a hobby project, I created a pretty handy mobile application for Salesforce.com Adoption that can be downloaded from the AppExchange that can compliment my other Adoption app that I created.

Instead of buying new licenses when you have a new user, try deactivating users that haven’t logged in within the past 30/60/90/120 days. Why not just deactivate one of the users that you gave an account that has NEVER logged in before?

Adoption Manager allows you quickly to see who hasn’t logged in in the longest time (or never) and deactivate them. It also allows you to reactivate any old user in the system or create a brand new user. Search through the entire database if you do not want to filter through lists and know a specific user to activate/deactivate.

What makes this even better is that this app can be accessed via the browser or your MOBILE browser. iOS/Android apps are coming soon, but this won’t hold you up, because of this mobile optimized app, using OAuth to securely login to Salesforce.com.

Manage your users quickly and more effectively on the go!

View AdoptionMax on the Salesforce.com / Force.com AppExchange here

Salesforce Adoption

Salesforce Adoption

Salesforce Adoption

Download Adoption Manager here


Tags: , , , , , , ,
Posted in Announcements, Force.com User Adoption, User Adoption | No Comments »

Salesforce.com User Adoption – New AppExchange Application

Written by ShamrockCRM on August 16, 2011 – 8:00 am

I am excited to announce a new product created by Shamrock CRM built specifically for improving user adoption in Salesforce.com and Force.com.  Imagine having 1000 users and only 50% user adoption. @ $1000/license, this is $41,000 WASTED in licenses/month.

Welcome to the solution, AdoptionMax – Salesforce.com User Adoption Management!

AdoptionMax

Try AdoptionMax on the AppExchange Here (Click View Screenshots to see More)

Take a look at my overview of AdoptionMax Here

With Adoption Max, you can send regular notifications to users and their managers/adoption champions based on certain levels of inactivity. Notify users by email, chatter posts, tasks, reports. Customize when to send messages, to whom, and how they should be sent. All of these notifications are customizable, reportable, and automatic. Turn the app on and forget about it. All notifications will be handled by the app.

Salesforce User Adoption

The best way to obtain user buy in is to establish a level of accountability. Users MUST know what you expect from them and they must be held accountable for their successes/failures. Adoption Max will provide them and their managers will visibility into their system usage or lack thereof.

We suggest establishing “Adoption Champions.” These would be power users that are responsible for the adoption success of a certain group of users, such as a region, an office, a product line, etc. These adoption champions would be assigned in Adoption Max and would have their own adoption reports to monitor. They would communicate with users to encourage usage of the system and regularly report to management about the level of adoption progress. e.g. A European Adoption Champion might be based in London and be responsible for all users in Europe. They would encourage usage, provide tips & training, help users when needed, and escalate to user management if there is lack of performance. The user, the user adoption champion, and the managers should all be held accountable for the adoption success. Adoption Max makes this VERY visible.

User Adoption Tracking

 

Read more about AdoptionMax and how it will improve your User Adoption here

Try out AdoptionMax on the Salesforce AppExchange

Let me know if you would like to try it out for FREE or if you would like more information.

Thanks for reading.  We have just found that SO many companies, big and small, have huge problems with user adoption management.  We want to help!


Tags: , , , , , ,
Posted in Force.com User Adoption, Salesforce.com, User Adoption | No Comments »