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

Showing Chatter Pictures without being actively logged in

Written by ShamrockCRM on August 16, 2012 – 1:03 pm

I am developing some PHP code that requires displaying Chatter photos on a web page. The code does not maintain an active browser session with something like OAuth. It simply logs in with the SOAP API, accesses the data, and displays data. Since Chatter photos are stored internal to Salesforce.com and require an active session, this causes an issue. Well, I found a great blog posts that solves this problem. Take a look here if you ever run across this problem.


Tags: , , , , , ,
Posted in API, Chatter, PHP, SOAP | Comments Off on Showing Chatter Pictures without being actively logged in

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 »

Geolocation in Salesforce Mobile Apps

Written by ShamrockCRM on June 12, 2012 – 12:02 pm

There’s not very often that I am astounded by something VERY cool having to do with SOQL, but here’s a goodie.  Salesforce is providing the capability for mobile apps to search for records in the vicinity of the current mobile user in SOQL.  Take a look at this information:

 

Geolocation

This one might be news to many Force.com developers, but one of the most exciting new features in Summer ’12 (currently in Pilot) is the addition of a Geolocation custom field type. You can now geocode data in Force.com by adding latitude and longitude coordinates using that custom field type. Once the data is geocoded (say in the location__c field), you can then execute a SOQL query like the one below from the mobile application

SELECT caseNumber, location__latitude__s, location__longitude__s FROM Case
WHERE DISTANCE(location__c, GEOLOCATION(&lt;latitude and longitude coordinates of mobile device&gt;), 'mi') &lt;= 10

The above query will return all Case records that are within a 10 mile radius of the mobile device. We’ll be providing additional details and code samples on how to use the new geolocation field type (pilot) in the near future, but hopefully the snippet above demonstrates some of the power of this new feature.


Tags: , , , ,
Posted in Summer 2012 | Comments Off on Geolocation in Salesforce Mobile Apps

Default values and tracking on Web to Lead forms

Written by ShamrockCRM on July 18, 2009 – 8:36 pm

If you have ever wanted to set default values for certain fields when someone is filling out a Salesforce.com Web2Lead form on your website, you absolutely can.  For example, let’s imagine that you have 5 product pages on your website and you have a contact form on each page.  You could set a field called “Originating Web Form” to the value Product 1 or Product XYZ as seen below.  The user filling out this form would never see this field that is filled out behind the scenes, because it is a hidden field.

This allows you to set fields in Salesforce that might trigger different types of workflow rules or could be used for specific marketing tracking.  This is a great, easy way to prefill in data or track certain behavior.

The line below allows you to specify a hidden value that the user does not see.  This will default a field in Salesforce.com called “Originating Web Form” with the value “Product XYZ Page.”  This will let you know that the user filled in the form on this specific product page.

salesforce.com development web 2 lead


Tags: , , , , , ,
Posted in Salesforce.com, Web Development | 2 Comments »

Adding Google Calendar to your Salesforce Homepage

Written by ShamrockCRM on July 16, 2009 – 8:08 pm

Did you know that you can embed your shared Google Calendar directly on your Salesforce.com home page?  Well, this can easily be done and it is a GREAT feature.

First, go to your Google Calendar page and click the “Settings” link on the left.

Next, select the Calendar you are interested in…in my case, Consulting.

Salesforce.com Gmail Google Calendar

Next, you will see a section where you can receive code to “embed” your calendar on a web page.  Copy the code.

Salesforce.com Google Calendar

Now, go into Salesforce setup and go to the Home Page Component section.

Add another Home Page Component of type “HTML Area.”  Hit the “View in HTML” checkbox and paste in the code.  Save.

Salesforce.com Google Integration

Now, add this home page component into a Salesforce.com Home Page Layout  and take a look at your system wide shared Google Calendar!

Watch Salesforce show you how to do this on video!


Tags: , , , , , ,
Posted in Google, Salesforce.com | Comments Off on Adding Google Calendar to your Salesforce Homepage

Populate Custom Lookup Fields from an S-Control

Written by ShamrockCRM on April 4, 2009 – 12:00 pm

Probably the most common request I receive from clients is to automatically populate a new record with fields.  This is a simple process, usually involving an S-Control and some URL parameters.  It gets a little more complicated, however, when you start wanting to populate lookup fields on the new records.

Warning:  This isn’t documented or supported by Salesforce, and could change at any time.

First, you need the ID of the field in question.  If you’ve already created S-Controls to populate new fields, this probably isn’t new to you.  However, if you haven’t, the easiest way is to navigate to the field in question in Setup. (Create > Objects > Object Name > Field Name, for custom objects).  Then, take the ID from the URL of the custom field, for example:

http://ssl.salesforce.com/00N50000001xxxx

You’ll want to pass this as a URL parameter when creating your new object, with “CF” preceding the ID and “_lkid” appended.  You’ll also want to provide a value for the textbox, as the ID isn’t enough.  So you’ll want to pass something like this for a Contact:

?CF00N50000001xxxx_lkid=00N50000001yyyy&CF00N50000001xxxx=John%20Doe

Basically, it just comes down to knowing to append “_lkid” to the ID of the field you’re passing in with the Salesforce ID, as well as providing a value to display in the textbox on the creation screen.  Hopefully this helps you out!


Tags: , , , , ,
Posted in S-Controls, Salesforce.com | 3 Comments »

Salesforce.com Lead Activity History Report

Written by ShamrockCRM on March 30, 2009 – 9:15 pm

I would like to show you a pretty effective Lead Activity History Report that I have been using in Salesforce.com.

This report is a typical Lead Report based off of Last Activity and Created Date.  I have added a few additional components to assist in the day to day process of following up on Leads.

I have added 2 formula fields:
1) Days Since Created – a number field
2) Days Since Last Activity –  a number field tracking the amount of days since the last Email sent to the Lead, Call logged with the Lead or Event scheduled with the Lead.

I filter my report by all Leads created within the last 45 days, because many Leads have a waiting period on budget, etc.

I use a combination of the Rating (Hot, Warm, Cold) field, the Status field (Contacted, Open, Qualified, Unqualified, etc), Estimated Project Value and the Days Since Activity field to generate an IMAGE formula field.  This image formula field is either of a Red or a Yellow flag to say “HEY, Red Flag, this person needs to be contacted immediately, because it is either a hot deal and too many days have passed since activity or it is a warm deal of high value and too many days have passed!”

This is absolutely wonderful, because you can easy look across your list of Leads without too much analysis and realize if something needs to be done.  It won’t show Unqualified Leads, so these won’t confuse you on your report.

I have also generate an “Importance” IMAGE formula field that takes into account the Lead Rating, Status and the Est. Project Value to show a stoplight.  Green means GO PURSUE, Yellow means COULD BE GOOD, Red means DON’T SPEND TOO MUCH TIME.  This will tell me that even if an Activity is not needed, keep an eye on this record, because it is Good, Bad or Ugly.

Salesforce.com Lead Activity History

*Image from dev account

What is great about this is you can put these IMAGE formula fields and “Days Since …” fields directly on your Leads dropdown lists views for easy viewing as well.  See the screenshot below.

Lead Management

As you can see, this is a great way to operationally manage your own Leads and the Leads of your employees!


Tags: , , , , , , ,
Posted in Business Analysis, marketing, sales, Salesforce.com | 3 Comments »

Free Salesforce.com S-Control to Dynamically Auto Refresh Dashboards

Written by ShamrockCRM on March 14, 2009 – 3:06 am

Ok, I have received many positive comments about this functionality that I posted about before regarding the auto refreshing of either a home page dashboard or an individual dashboard when a user simply visits the page.

I know that Salesforce offers the ability to schedule dashboards, but this is really to be used in the case of an organization having MANY dashboards and a Salesforce.com Administrator not wanting to schedule hundreds of dashboard refreshes.

Take a look at my original post explaining this Salesforce.com Dashboard Refreshing functionality

I am going to provide this useful code for you to use for free.  This is once again a very simple piece of code, but somewhat useful and unique.

1) Create an S-Control called whatever you’d like.  I called mine “Auto Refresh Dashboard.”

2) Paste in this code:

<code lang="html">&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
function clickButton(){
var thebutton = parent.document.getElementsByName('refresh');
thebutton.item(0).click();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="clickButton()"&gt;
&lt;/body&gt;
&lt;/html&gt;</code>

3) Create a Home Page Component of type “HTML Area.”
4) Click “Show HTML”
5) Paste in the following code:

<code lang="html">&lt;iframe name="rss_iframe" src="/servlet/servlet.Integration?lid=XXXXXXXXXX&amp;ic=1" width="0%" height="0"&gt;&lt;/iframe&gt;</code>

6) Replace XXXXXXXXXX with the Salesforce.com record ID of the S-Control that you created above.
7) Add this home page component to your home page layout.

Now, the home page dashboard will always automatically refresh when Users visit their home page, preventing confusion by keeping data up to date!

Have fun!


Tags: , , , , , , ,
Posted in dashboards, S-Controls, Salesforce.com | 13 Comments »