Free JQuery Mobile Adoption Manager JavaScript Code

Written by ShamrockCRM on August 26, 2012 – 9:03 pm

This is Part 3 in the series of Salesforce.com HTML5 Mobile Development using VisualForce, APEX, JavaScript (JQuery Mobile) and HTML5.  I have already posted the code for the Visualforce as well as the APEX Controller.  This part in the series provides you with the JavaScript code to finalize everything.  The combination of all of this will show you how to implement this Adoption Manager AppExchange app for managing the adoption of your users.

A couple of notes here.  This code is certainly not optimized and certainly not prettied up.  A lot of the functions need to be merged into cleaner functions.  The memory usage could probably optimized a little better.  There are a couple of other things to play with as well.  This is basically a way to help you learn how to implement different features using Salesforce.com in HTML5 with JQuery mobile, such as querying profiles and dynamically populating a form picklist and displaying lists of users on the screen and activating/deactivating users, etc.  Take what you will from this, but it is a fully functional mobile app for you to hack and place into PhoneGap if you would like.

Salesforce JQuery Mobile

This code goes into the usermanager.resource static resource (after the break).
Read more »


Tags: , , , , , , , ,
Posted in Salesforce Mobile, VisualForce, Web Development | Comments Off on Free JQuery Mobile Adoption Manager JavaScript Code

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 | Comments Off on Salesforce Mobile Dev Part 2 – APEX Controller

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 »

Salesforce for iPhone and iPad

Written by ShamrockCRM on December 21, 2011 – 9:03 am

Salesforce released iOS apps well before any glimpse of Android applications, so here is a quick preview of what is available from iTunes.Salesforce iPhone iPad Apps

Salesforce Mobile – the original iPhone app.  It is still VERY basic in the overall UI experience, but it will allows you to accomplish a lot.  Create/Edit/View your standard and custom objects.  View dashboards.  Log activities.  It is certainly not pretty, but if you have an iPhone (or even an iPad) and use Salesforce, this is a must.  It can even be used as a quick way to build very basic iPad applications, but it will not scale up in a pretty way.

Salesforce for iPhone

Salesforce Chatter – Works great for both the iPad and iPhone.  Outstanding collaboration app for your iOS devices.  I wish Chatter functionality was built directly into the Mobile app above, but I understand that they are marketing to more customers than just CRM and want a standalone product.  CRM feels neglected.

Salesforce Mobile Dashboards – Fairly straightforward and to the point.  View your dashboards on a big screen on the iPad.  Great standalone app to prevent confusing executives!

Salesforce Mobile Dashboards

 

Dragon for Salesforce – Free standalone app to utilize the Voice to Text features provided by Dragon software.  Who really wants to type about their site visit or call log on their tiny mobile phone keyboard when they can just speak.  Pretty nice.

Dragon Salesforce Mobile

I’m very excited for Touch.Salesforce.com and the mobile capabilities that should hopefully spur from the usage of HTML5.

 

 


Tags: , , , ,
Posted in Chatter, Salesforce Mobile | Comments Off on Salesforce for iPhone and iPad

Salesforce for Android – Mobile App and Chatter

Written by ShamrockCRM on December 20, 2011 – 5:35 pm

Salesforce Android App

How did I seem to miss this news.  There is a Salesforce app for Android now?  It seems so.  But of course, in typical Salesforce style, it is released with minimal features.  It is read only with no edit/create capabilities, very similar to the iPhone Salesforce Viewer app.  C’mon Salesforce!  Try it out here.

In addition to that, Salesforce Chatter has been released for Android and looks pretty great on tablets if you happen to have one.  Looks like Salesforce is finally giving Android a little love.

Chatter Android


Tags: , , ,
Posted in Google, Salesforce Mobile | Comments Off on Salesforce for Android – Mobile App and Chatter