Pages

Tuesday, November 6, 2012

Removing the Magic, Applying the Science, Keeping the Force

I'm very excited and happy to announce that I have joined Ami Assayag (@amiassayag) and his company, CRM Science  (www.crmscience.com), as a Salesforce.com developer.



Be sure to check out www.crmscience.com and follow us on Twitter @CRMScience for the latest and greatest.

If you're in the Philadelphia area, be sure to check out the PhillyForce Salesforce User's Group (http://www.meetup.com/PhillyForce).  It's a great community with a great number of area experts that offers monthly meetups and fairly regular co-working sessions during the week.  (@PhillyForce)



Wednesday, September 19, 2012

Dreamforce '12 - Red Hot Day 2

Today boils down into Keynotes and the Gala.


The keynote featured success stories from many clients, using many of the new in '12 sister sites.  The School of Rock is an example of this and they demonstrated how their school functions with Do.com.  Two announcements made for Do.com were an Android app and a now open API for developer use.

Then on came MC Hammer, performing with his crew "Too Legit to Quit" and "Can't Touch This."

Next came a quick segment that seemed fairly recycled from last year, touting the evolution of computing and its shift from on-premise servers and hardware to the cloud.  These changes are fostering the "Social Revolution" in which Salesforce.com is proud to be part of.

The rest of the keynote were success stories from GE, Rossignol, Charles Schwab, Activision, Yelp, Commonwealth Bank, Virgin America, and Facebook.  Marc Benioff's vision of General Electrics future was interesting and in short form think of engines with APIs, dumping data into Salesforce for analysis.  I saw this on a smaller scale in the Dev Zone yesterday with the Fitbit.  My highschool Cisco networking professor, Mr. Thomas, predicted this over a decade  ago when he said everything will talk to everything and collect information about itself.  Data is king.

The Fireside Chat with Marc Benioff and Sir Richard Branson started off interesting and then seemed to snowball off-topic.  I enjoyed hearing about Branson's start and how he became who he is, but the conversation quickly turned to politics and my ears went numb; tuning in and out.  Benioff inquired Branson's stance on the war on drugs.  A cheer erupted as Branson announced the war on drugs was a failed effort and he would like to see countries "decriminalize" drugs (note, not legalize) and treat their use the same as you would treat alcoholism.

The Gala this evening was very enjoyable.  7-8 blocks away from the Moscone Center, City Hall was set up to entertain this year's almost 90,000 Dreamforce attendees.  Starving from a long day, we were first greeted with popcorn.  Popcorn turned into tents with gazpacho, BLTs, shrimp coctails and tons of beer and wine.  Hiking deeper into the lawn area, more food tents contained quite an array of food including fish and chips, nachos, meatballs, pizza, and more.

Red Hot Chili Peppers came on a little after 8:15 and played their greatest hits, new and old (Can't Stop, By The Way, Dani California, Californications, Under the Bridge, Snow and others with Give It Away as the encore.








Tuesday, September 18, 2012

Dreamforce '12 - Day 1

I'm back in San Francisco again this year for Dreamforce '12.  After an (adventurous || adrenaline packed || terrifying || downright good time) weekend of climbing in Yosemite with CRM Science's Ami Assayag, I came to this city in a mentally prepared state to soak in as much as I can.  The older, wiser, and more experienced me thought I knew what to expect, but it seems #df12 has grown just as much as I have over the past year.

The number of attendees, venues, and sessions have all expanded.    Somehow, I managed to spend all of my day in the Moscone West building. 

Session #1: Unleash the Force.com User Interface with Skuid
Skoodat's Skuid seems like a great tool that would save a ton of time in developing custom page layouts or even stand-alone pages. Its drag and drop visual page editor reminded me of Frontpage or Dreamweaver as the code for the page is created for you behind the scenes. Within a few minutes, the presenters created a new multi-paned and tabbed Contact view as well as a custom list page. With a handful of clicks, they were able to add additional actions to each row of their data set. I'd love to see something like this become a general release feature

Session #2:  The 10-Year Evolution of Developers and Salesforce.com
This was another session that took place in the Developer Theater tucked behind the Dev Zone. David Claiborne of The Claiborne Company did a great job of showing how far Salesforce.com has come along over the last decade+. Apex and Visualforce haven't always been key components to the platform, neither have sandboxes or custom objects. This session made me realize that I began working with many of the modern enhancements of Salesforce.com as they were being released.

For a list of those features and to vote for your 3 favorite features visit: here

Session #3: Apex Design Patterns
Not coming from a developer background, this was one of the best sessions of the day for me. Not only were best practices discussed, but common development patterns applied to Apex were demonstrated. I can see future posts in my near future as I explore the 6 patterns presented.

  1. Singleton
  2. Strategy
  3. sObject Decorater
  4. Façade
  5. Composite
  6. Bulk State Transition


My other sessions of the day included:
Session #4:  JavaScript Patterns and Practices from the Salesforce Experts
Session #5:  Introduction to Heroku
Session #6:  Workbench:  The API Swiss Army Knife


The Expo (Moscone North) and Campground (between North and south) opened today at 2 and held a Welcoming Reception at 6.  Great food and drinks spread out among the vendors.  

Follow me on Twitter:  @kirkevonphilly
Join the PhillyForce Salesforce.com User Group:  http://philly.force.com/ 

Thursday, August 30, 2012

Day Changer: Chrome Extension - Force.com LOGINS

Today's Day Changer is a Chrome Extension named "Force.com LOGINS."

Download it here.

Why is it useful?  If you've got multiple Salesforce.com credentials to keep track of, this extension allows you to keep them organized.  Once you've entered them, it only takes two clicks to log into any instance in either a new tab or a new window.  Working on several different projects through out the day, I'm frequently in and out of production and sandbox orgs.  With this extension, I'm typing my credentials a lot less frequently.


Before you install it, take a look at the author's security note to decide if this extension will work for you in your working environment.  If not, there are plenty of non-Salesforce specific credential managers out there.

++++++++++++++++++++++++++++
Security Notice      (2012/3/7)
++++++++++++++++++++++++++++
This extension throws Force.com login username and password via POST when logging in with new tab, and via GET when logging in with new window.
Throwing information via GET means there will be URL containing username and password shown in the browser history.

For those of you who do not want your username and password shown in your browser history, please do not use 'window' button to login with new window.

Please also be aware that if anybody has access to your chrome browser, he/she can look into localStorage where all your force.com credentials are stored in.
Your credentials are not encrypted since anybody can look at the source code of the extension and somehow decrypt it.
++++++++++++++++++++++++++++


Wednesday, August 22, 2012

Day Changer: Dexpot Virtual Desktops for Windows

Day Changers are those tools you stumble upon that make an impact on your day to day Salesforcing. Today's Day Changer is one that helps me maximize the use of my laptop screen.

When I was with my old company, I fully embraced the power of multiple monitors. When I started, I had a 15" CRT beige box. When I left, I had a triple-headed monster. 21" widescreen monitor in portrait mode on the left for coding, 21" widescreen center monitor, and a 19" square for email/reference.

Anyway, now that I'm on my own, I don't always have the luxury of multiple monitors. I work off of a laptop and at best I get to work at my desk with an additional 21" lcd. Most of the time, I'm working off of my laptop's 13.3" screen.

Ouch.

Granted you can get by, but it's hardly efficient. Shortcuts like ALT+Tab are useful, toggling windows and keeping my hands on my keyboard, but I need more.

I'm a big fan of the virtual desktops found in many of the linux flavor. A quick CTRL + Alt + left, right, up, or down and I'm on another desktop with its windows exactly where I left them.

However, try as I might, I've yet to find equivalents for all of the tools I use on a day to day basis. But what if virtual desktops existed for Windows?

That's where Dexpot comes into play. A quick download, install, and a few key key assignments later I was good to go. The tool is quite flexible and offers several additional plugins like Dexgrid and Dexcube for additional eye candy.

You can configure additional desktops if needed, but I easily get by with 4 in a 2x2 grid. My top-left desktop is usually the Force.com IDE/Eclipse. Top-right is a Chrome window with multiple tabs (all within the same SF instance). Bottom-left is usually the Developer Console or a Debug Log window for testing. Bottom-right is my leftover desktop - maybe another Chrome window, Evernote, Notepad++, whatever I need.

I can keep everything logically organized on these additional virtual screens and without taking my hands off the keyboard, I flip over to another screen and quickly switch back. Adding an additional key and using CTRL+ALT+Shift and an arrow key, I can move the active window over to another virtual desktop.

If you do have multiple monitors, you can utilize them as well. Or not, by turning disabling Dexpot for those displays.

Bonus Tip #1: Windows key + arrow left or right to resize and snap a window.

Bonus Tip #2: There are shortcomings of the above shortcut key. For instance, monitor orientation is not taken into consideration. Snap a window to a portrait mode monitor and you end up with a long thin column of a window. Not too useful. That's where GridMove (http://jgpaiva.dcmembers.com/gridmove.html) comes into play. You can create custom zones and assign keyboard shortcuts to snap windows into each. For example, on my 19" square, I broke it up into 2 rows; the top half dedicated to Outlook and the bottom equally split between Evernote and Notepad++.

Friday, June 1, 2012

Using Change Sets

A question came to me this morning from someone who had certain components built out in a a sandbox and needed them to be replicated in production. The components in this scenarios were page layouts; something easy enough to rebuild manually, but if you have dozens of fields, either of these methods would be faster.

  1. Eclipse
  2. Change Sets

They both require a few additional steps, but both prevent you from having to reproduce your work. Since we are dealing with page layouts, the first thing you need to make sure of is that all the fields referenced in the page layout exist within your production instance. You'll definitely receive error messages upon trying to deploy a layout to an object that is missing fields.

Using Change Sets

The Change Sets method will be easier for non-developers that don't know their way around Eclipse. This method will allow you to build Outbound Change Sets bu adding and removing components, and then uploading them to any allowed Deployment Connection. Let's start there by allowing establishing a Deployment Connection between your sandbox and your production instance which will allow you to upload Outbound Change Sets to Production for deployement.
  1. First, within your production instance, click on your name at the top of the page, and then click on "Setup" On the left-hand side, under "App Setup," expand "Deploy" and click on "Deployment Connections"
  2. Find the name of your sandbox and click on the "Edit" link next to it
  3. Check off the box that says "Allow Inbound Changes" and then click on the "Save" button.
The next thing to do is to create an Outbound Change Set within your sandbox. For this scenario, the change set will include a page layout that I want to deploy within my production instance as well as a new field that I added to the object within the sandbox. One change set, two components, one deployment. Nice!
  1. Within your sandbox, click on your name at the top of the page again and then click on the "Setup" link
  2. On the left-hand side, navigate to "App Setup" --> "Deploy" and then click on "Outbound Change Sets"
  3. Click on the "New" button to create a new Outbound Change Set
  4. Provide a "Name" and "Description" for your change set.
  5. Click on the "Save" button.
  6. Within the "Change Set Components" section, click on the "Add" button.
  7. First, let's add the new field. Change the "Component Type" dropdown to "Custom Field"
  8. Next, find and select any fields that you also need to deploy that are not currently found in production.
  9. Click on the "Add to Change Set" button at the top of the page. Here's a quick tip -- make sure that you use the "Add To Change Set" button after you select something. Changing the component letter, page, or "Component Type" will clear any previous selections.
  10. Now it is time to do the same for the page layout. Change the "Component Type" to "Page Layout, find and select your new layout, and then click on "Add To Change Set" again.
  11. Your change set should have two components in it now.
  12. To push your Outbound Change Set to the Production instance for deployment, click on the "Upload" button.
  13. Choose your Production instance and then click on "Upload"

Within a few minutes you should receive an email, letting you know that your Change Set was uploaded to the production instance. Keep in mind that you don't always have to push from a sandbox to production. You can go from sandbox to sandbox or even production to sandbox.
Once you do receive that email, it is time to deploy it.
  1. Within your sandbox, click on your name at the top of the page again and then click on the "Setup" link
  2. On the left-hand side, navigate to "App Setup" --> "Deploy" and then this time click on "Inbound Change Sets"
  3. Click on your change set. Here you will be able to see information about the change set, including its components, any details, and its deployment history. You also have two options; "Validate" and "Deploy."
  4. Clicking on "Validate" goes through all of the actions required to deploy the change set without actually deploying it. This is always a safer bet as you can learn which components will be new, overwritten, or deleted. Sometimes you learn things from a validation that you didn't expect and can save yourself from making mistakes.
  5. "Deploy" first validates and if all is well will deploy your change set. Keep in mind that if you've added new layouts, they won't be assigned to a recordtype yet, so you'll have to do that manually. If you added fields, permissions won't be set up on that field as they would be if you were to manually create the field. The same goes for picklists options and their recordtype preferences.

Thursday, May 31, 2012

Server Monitoring - Disk Space Batch File

Weeks ago we began down a road, experimenting with the idea that you could monitor servers with Salesforce.  I did mislead you; Salesforce isn't doing the monitoring, but will be responsible for creating notifications (through workflow) and give additional metrics for future systems reporting.

We've already created an object called "Alerts" to place information into (records that could cause sys admins night sweats and tremors).  That object has two fields, basically who (the node) triggered the alert and what (the conditions) the alert is for.

The next step is to create and schedule a batch. The batch below will take two parameters - the drive letter that you want to monitor and the low disk space threshold in MBs (i.e., "Disk_Space_Alert.bat C 20480" would monitor the C:\ and create an alert when the amount of disk space was 20480MBs/20GBs or less)
@ECHO OFF
setlocal

REM - This issues the DIR command on the disk letter provided, pipes it
REM - into FINDSTR, looks for the line where "free" is located, and places that
REM - line into a temp file
REM - Then it converts that line into tokens and assigns the number of free bytes
REM - to the FREE_BYTES variable
dir %1: 2>&1 | findstr free > temp

for /f "tokens=3,4*" %%f in ( temp ) do (
     set FREE_BYTES=%%f
)

REM - This removes commas and decimal points from FREE_BYTES

set FREE_BYTES=%FREE_BYTES:.=%
set FREE_BYTES=%FREE_BYTES:,=%

REM - The following line takes the number of free bytes and uses Powershell
REM - to calculate the number of MBs and assigned as a string variable
REM - This was done due to batch files numbers being limited to 32-bits of precision


FOR /F %%B IN ('powershell %FREE_BYTES%/1024/1024') DO (
    SET FREE_M_BYTES=%%B
)

REM - Next the decimals are removed and assigned to an integer variable

FOR /F "tokens=1* delims=,." %%B IN ("%FREE_M_BYTES%") DO (
    SET /A FREE_M_BYTES_INT = %%B
)

REM - Here we assign the threshold limit parameter to a variable

set /A LIMIT=%2

REM - Next, if the number of free MBs is less or equal to the limit
REM - a CSV is created. First the headers, then the alert fields
REM - After the file is created, process.bat is called to initiate the insert
REM - into Salesforce. Don't forget to install Data Loader, change your path
REM - and see my next post about the config file


IF %FREE_M_BYTES_INT% LEQ %LIMIT% (
    echo RESOURCE, DETAILS > alert.csv
    echo %COMPUTERNAME%, Low Space on %1 - %FREE_M_BYTES_INT% MB remaining >> alert.csv
    C:Program Files (x86)salesforce.comData Loaderbinprocess.bat ../conf Disk_Space_Alert
)

So in a nutshell:
  1. Create the batch file
  2. Schedule the batch file
  3. When scheduling, you'll need to specify the disk letter and the MB limit (i.e., "Disk_Space_Alert.bat C 20480")
  4. The program will launch, check the amount of disk space on the specified drive
  5. The batch will then convert bytes to MBs and compare it to the limit specified
  6. If the limit is met or exceeded, a CSV is created and formatted with information about the issue
  7. Finally, the batch calls another batch file that initiates a Data Loader insert
In the next post, I'll discuss using the SF Data Loader from the command line and how my config file is set up.

Where'd He Go?

Hope you aren't feeling too neglected with my blogging absence!  I've been going through various life changes and preparing for the road ahead. 

Since my last post, I've peacefully and respectfully parted ways with my previous employer and excited to announce that I will be providing Salesforce administration and development consulting services as I further develop my own company on the force.com platform.

If you're interested in hiring, bouncing ideas off of, having a cup of coffee with, hitting the gym with, or any other activity in general where you want to discuss Salesforce projects with me, feel free to shoot me an e-mail at kirk@salesforcery.com.

There should be plenty of updates in the future weeks.  Summer '12 is out now with some great features and I'm already one post into a series on server monitoring (talk about a cliff-hanger).  Thanks to all the visitors that I've picked up on this blog over the past year; it's only going to get better!

...and seriously, it doesn't cost anything to email me, so here's that link again:  kirk@salesforcery.com.

-Kirk


Thursday, April 19, 2012

Server Monitoring - Alerts Object

The first thing that I'm going do is create the object in which my alerts are going to live in Salesforce.  For this example, I'm going to create a dedicated custom object for this.  You may want to use Chatter or even incorporate it into your existing structure; perhaps you have some sort of IT inventory (who doesn't?) objects that you can connect to.

The basics of what we need are:
  • The resource - what device is having an issue
  • The alert - details about the issue the resource is having (low disk space for our usage)
This is how I'm configuring the object on the "New Custom Object" page:


I've checked off both "Allow Reports" and "Allow Activities."  Ideally, when the alerts are configuring and being dumped into Salesforce, I will be building workflow to send off some e-mails.  Then I'll begin building a few reports for any notifications over the course of time - scheduled weekly emails of low system resources sounds kind of cool.  Imagine that patterns you could observe over the course of a few months.  I've also enabled notes and attachments as I imagine this could be used for future issue identification and resolution as well.  Feel free to create a tab for this if you'd like.

Once the object is created, I've got my shell of an object with the basic fields:
  • Alert Name - auto number
  • Created By
  • Last Modified By
  • Owner
Now I'm going to add my two custom fields mentioned above and listed below:
  • Resource
  • Details

I've required that the "Resource" field be populated at the field level.  Don't forget to set the correct permissions for these fields based on profiles on the following screen.

Not a lot of rocket science in this post, but at least now we've got our object for which we'll insert our alert records into.  The next posts will be a little more exciting and cover creating and scheduling a batch file for performing a disk space checks and creating a Windows Perfmon alert.













Friday, March 23, 2012

Server Monitoring - Project Description

It's a very Salesforce Friday; the weather is nice, my fingers are flying, and most importantly my code is saving without errors!

I'm hoping the description got your attention on this one and you wondering how in the world Salesforce is going to monitor your servers.  Well, I've fed your assumptions a half-truth.  At this point, Salesforce isn't going to be doing the monitoring (yet?); it will be simply providing to you notifications.

I know, I know - you've got high-end systems in place doing all the server monitoring you could ever dream of full of alerts, notifications, bells, whistles, and some Rita's Water Ice on top of that too (you know, in honor of it being Spring).  Don't overlook the point of this series; it isn't to just create a custom object that will trigger some workflow.  It's about being able to tie together three or four different pieces of software to build an entire system that leverages the flexibility of Salesforce (and because all roads will inevitably lead to Salesforce).  Not just a system, but something that can easily be expanded an built upon.

Here's what I'm thinking:

Monitor a server
Use Perfmon - Memory Usage
Use a command-line utility - Hard disk utilization

Create Alerts
What's wrong with who

Import Process
Get that info into Salesforce so we can use it
Where's the data going to live?

Dashboard/Workflow
What are you going to do with that data?

Stay tuned!  We're going to have some fun with Perfmon, batching, Data Loader, and some VF.

Thursday, March 15, 2012

One View to Rule Them All

Scenario:  I was working on customizing a project management app and needed a quick view named "My Projects" that would allow a user to see only the projects in which they were listed as the "Project Manager."

"Project Manager" was a custom User lookup field.  It seemed erroneous to instruct users to create their own views.  There had to be a way that I could create it once and it would provide the correct results for each user.

When you are on the "Create New View" screen, unlike when you are writing a workflow rule, you don't have the ability to create formula based criteria; only the "Filter By Additional Fields" field-operator-value drop downs are available.
IdeaExchange:  https://sites.secure.force.com/success/ideaView?id=08730000000K149AAC




Unfortunately, the Owner of a Project record won't necessarily be the Project Manager, so using the "My Projects" filter won't work (wouldn't it be nice if for any "My" option, a list of User lookup fields would appear that you could select from?)
IdeaExchange:  https://sites.secure.force.com/success/ideaView?id=08730000000grYFAAY


To create one view to rule them all, I ended up creating a formula field that would compare the current user's ID to the Project Manager field and return either 0 or 1.


IF($User.Id = Project_Manager__c, 1,0)


Now that you have your field, any record that you are looking at in which your User ID matches the ID found in the Project Manager field, the "PM is Me" formula field should read "1."


That being so, you can create your view with a single criterion:

That's that!



Monday, February 13, 2012

There's a Hole in My Bucket!

Ah, for many Salesforce users, Spring '12 was rolled out over the weekend. There are lots of new features that I've been chewing on in the pre-release sandbox and a few surprises.

One of the new features is the ability to create report "Buckets." Buckets let you create groups for a field's data without needing to create a formula field. I can't tell you how many formula fields I've created just to display the information I want to see on a report correctly. Of course - these bucket fields exist only on the report you're creating, so if you want to base workflow off of the field, it is off to the formula field editor for you.

Say you've got your list of clients, all equally important to you (of course), but you'd like to group them by the amount of assets they've brought to you. I'm not saying my Gold level clients are going to receive any special treatment over the Bronze level - I just want to know... really.

I'm going to classify my clients, using three tiers:
Gold: Anyone over 3,000,000
Silver: Between 1,000,000 and 3,000,000
Bronze: Below 1,000,000

1)  To create a new Bucket field, within a new/existing report, click on the "Add Bucket" link within the fields section.



2)  Next, double-check your "Source Column, give your Bucket field a name, and define your ranges:

3)  Click on the "OK" button and you'll see your newly created "Service Level" field within your report grid:


 
Unfortunately, like many initial rollouts of SF (I'm looking at you lookup field filters), it is lacking the ability to create and use filters.

What if I had a client that has been with me from day one.  Sounds like an instant Gold Service Level criterion to me.  It would be great to be able to include something like "Initial Contract Date < 1/1/2005" = Gold, else follow the ranged criteria.

For more information, check out this video, by my new favorite SF video narrator:  http://www.youtube.com/watch?v=QFYEtBtLHG4

Saturday, February 11, 2012

Don't Double Quote Me!

I came across an odd bug within a Visualforce page yesterday.  At least I think it is a bug - I can't explain it and it has been esclated to an upper tier of premier support.

Within an <apex:outputPanel />, I was using a "rendered" formula within the tag:

<apex:outputPanel rendered="{!If(AND(myObject__c.relatedObject__r.theSuspectField__c = 'The Picklist Value',myObject__c.myField2 > 0), true,false)}">


Ater I saved the page (and although the page would save), I started to receive warnings that I needed to close my tag. Thinking that was strange, I commented out everything between my and tags and received the same thing. Then I saw my rendered formula - that's strange, I must have used double quotes by accident. This is what I saw:

<apex:outputPanel rendered="{!If(AND(myObject__c.relatedObject__r.theSuspectField__c = "The Picklist Value",myObject__c.myField2 > 0), true,false)}">


I replaced the double quotes with single ticks again, hit save, and bam - they were converted to doubles again.

What gives?

Eventually I figured out that if I changed the order in which my fields were listed, the record would save as expected - no double quotes:

<apex:outputPanel rendered="{!If(AND(myObject__c.myField2 > 0,myObject__c.relatedObject__r.theSuspectField__c = 'The Picklist Value'), true,false)}">


I'm assuming that this it has something to do with myObject__c.relatedObject__r.theSuspectField__c being a picklist field, located on a related record.  Why it works in an alternate position in the formula, beats me, but is probably one of those strang quirks of Salesforce.

I'll update as I find out more.

Note:  I was using the inline VF editor, but saw the same issue when I attempted to resolve the issue within the Force.com/Eclipse IDE.

Tuesday, January 3, 2012

VF Templates: Formatted Merge Values (dates)

Just like in the previous post, another type of field that you might not receive your expected data format are date fields.
My record said: 

This is the VF code I was using:
{!relatedTo.myDateField__c}

The resulting text displayed in an email was:

That's not too pretty.
For date fields, you can extract individual pieces of the date, including the month, year, and date.  Once you pull those pieces out, you can separate them with a forward slash (“/”) and then it will look more like the date field you were hoping for.

I'm hoping for something that looks like "1/3/2012."

To retrieve the "1" for the month:

{!month(relatedto.Distribution_Form_Received_Date__c)}

To retrieve the "3" for the date:


{!day(relatedto.Distribution_Form_Received_Date__c)}


To retrieve the year "2012":

{!year(relatedto.Distribution_Form_Received_Date__c)}


Put them all together with those forward slashes:
{!month(relatedto.Distribution_Form_Received_Date__c)}/{!day(relatedto.Distribution_Form_Received_Date__c)}/{!year(relatedto.Distribution_Form_Received_Date__c)}


With that little bit of magic, your end result will be:

Monday, January 2, 2012

VF Templates: Formatted Merge Values (currency)

Once in a while, I'll run across something that I've forgotten all about.  Today, I was working with a Visualforce e-mail template that contained a currency field as one of the merge fields.

My record said:  $99.00
I was pulling it in with just this VF code:

{!relatedTo.myCurrencyField__c}

Just doing that resulted in the template displaying:
Not quite what I was looking for.  What I ended up doing was throwing my merge data into a pre-formatted apex:outputText field, using an apex:param:

<apex:outputText value="{0,number,$###,###,##0.00}">
    <apex:param value="{!relatedTo.myCurrencyField__c}" />
</apex:outputText>

This will format the dollar amount up to $999,999,999.99.  The 0's are there just incase your amount is not a full dollar ($0.89) or an amount that ends in 0 ($25.40).  Otherwise, those values are truncated ($.89 and $25.4 respectively).

Now the template looks like this:





To see more of what you can do, check out:  Java MessageFormat

Wednesday, December 21, 2011

Now you see it... Now you don't!

Part of a recent project requirement was to display a set of fields on a record from a related record.  One possibility could have been formula fields for each related field that needed to be displayed.  Sigh...

Another would have been to open a second window on a second monitor.  Nah... too easy

Of course you could create a Visualforce page that pulls these fields in and add it to the page layout.  That would work, but ah... the panel is part of the page, meaning you scroll - it moves.  Suddenly you're scrolling up and down and you might as well have had two windows open.  Forehead slap!

What do you do?

I'm a huge fan of the Force.com Quick Access Menu; one of the best time savers rolled out in a recent release.

It's just a small menu panel that floats at the side of the page.  The cool part about this is if you scroll, it moves with you.  Now, how in the world are you supposed to recreate that?

Fortunately for me, I didn't want it always displayed.  Because of that, I knew I had access to Custom Links and Custom buttons (read more).  They aren't just good for linking to pages, you can use them for launching onClick Javascripts too!
//Start of Custom Javascript Button Code
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
 //Let's create a new DIV
var newdiv = document.createElement("div");
var result = sforce.connection.query("Select ID From ObjectID where ID = '{!ObjectID.ID}' AND other criteria if required);

//In my case, not every record would have a related record, so to avoid unnecessary errors we'll add make sure we have a result.  Granted, in your scenario, you may return more than one record.

if(result.size>0){
    var records = result.getArray("records");
    var newdiv = document.createElement('div');
    //I'm just going to build out my URL + parameters here
    var string1 = "apex/yourVFpage?core.apexpages.devmode.url=1&id=";
    var string2 = records[0].Id;
    var string3 = string1 + string2;
    newdiv.setAttribute('id', "thepanel");
    newdiv.style.width = "85%";
    newdiv.style.height = "255px";
    newdiv.style.position = "fixed";
    newdiv.style.left = "220px";
    newdiv.style.top = "0px";
    newdiv.style.background = "#FFFFFF";
    newdiv.style.border = "1px solid #000";
    newdiv.style.zIndex = "1000";
    newdiv.style.padding = "0px";
    //Use a regular old iframe to pull in your VF page
    newdiv.innerHTML = "<iframe src='"+string3+"' width='100%' height='240px' scrolling='false'/>";

//This DIV displays the up arrow graphic and provides the onClick functionality for hiding the panel
    var newdivUp = document.createElement('div');
    newdivUp.setAttribute('id', "UpPanel");
    newdivUp.style.width = "46px";
    newdivUp.style.height = "46px";
    newdivUp.style.position = "fixed";
    newdivUp.style.left = "174px";
    newdivUp.style.top = "0px";
    newdivUp.style.background = "transparent";
    newdivUp.style.zIndex = "1000";
    //Display the image and onClick hide this panel, display the down graphic panel, and hide the info panel
    newdivUp.innerHTML = "<img id='up' src='yourUpGraphic.png' onClick='document.getElementById(\"UpPanel\").style.display=\"none\";document.getElementById(\"DownPanel\").style.display=\"block\";document.getElementById(\"thepanel\").style.display=\"none\";document.getElementById(\"DownPanel\").style.display=\"block\";'/>";

//This DIV displays the down arrow
    var newdivDown = document.createElement('div');
    newdivDown.setAttribute('id', "DownPanel");
    newdivDown.style.width = "46px";
    newdivDown.style.height = "46px";
    newdivDown.style.position = "fixed";
    newdivDown.style.left = "174px";
    newdivDown.style.top = "0px";
    newdivDown.style.background = "transparent";
    newdivDown.style.zIndex = "1000";
    newdivDown.style.display = "none";
    //Displays the image and onClick hide this panel, display the up graphic and the info panel
    newdivDown.innerHTML = "<img src='youDownGraphic.png' id='down' onClick='document.getElementById(\"DownPanel\").style.display=\"none\";document.getElementById(\"UpPanel\").style.display=\"block\";document.getElementById(\"thepanel\").style.display=\"block\";' />";

//These three lines will add the DIVs created above to your page
    document.body.appendChild(newdiv);
    document.body.appendChild(newdivUp);
    document.body.appendChild(newdivDown);
}
//And just in case you don't return any records, display an error message
else if(result.size==0){
    alert('This record is not associated with an \'yourObject\' record. Please check the \'yourObject\' field and try again.');
}

Here's my end result in the "opened" state:

In the closed state:
And since you each DIV's position attribution to be "fixed", the panel, "x," or "+" will float at the top of your page for easy use when related data is needed for comparison purposes.

...or of course you could just open two browser windows.  Your choice.

Monday, October 24, 2011

Automated Phone Calls Via Workflow???

Sure, you've got four workflow actions that you can choose from when setting up your fancy new automated processes.
  • Tasks
  • Email Alerts
  • Field Updates
  • Outbound Messages
What if I said you could extend this to include:
  • Automated Calls
    • Pre-recorded messages
    • Robot voice messages (text-to-speech)
  • Text messages
Pretty sweet right?  Check out Call-em-All.  Let's get it out of the way now... I'm not affiliated with them and they were just a lucky Google search result that I found when searching for broadcast messaging solutions. Sign up for an account and then register for API authorization to get some test credits.

Through the GUI, you can setup call broadcasts; essentially the same as a mass e-mail, but with phone calls.  It's an easy service as all you do is upload your calls list (first name, last name, phone number) and record a message to be played.

They've got a great API that comes loaded with documentation, code samples, and a staging environment. 

You can leverage this to create some Apex that can be initiated by a button/link click, scheduled, or yes...even a trigger.

In the following sample, I will be initiating a call broadcast from my Opportunity by updating the Stage. Utilizing their text-to-speech feature, the call will dynamically include the Opportunity's name and stage. There will be two parts; the class and the trigger.

First, the class (excuse the body as it's lengthy):
public class Call_em {
@future (callout=true)
    public static void callMe(string a, string b){
        string Name = a;
        string stage = b;
        string username = 'username';
        string pin = 'pin';
        string broadcast_type = '1';
        string phone_number_source = '3';
        string broadcast_name = 'SAMPLE API Broadcast';
        string caller_id = 'caller_id';
        string PhoneNumbers = 'phonenumbers';
    string TTSText = 'This is a test call for the' + Name +' opportunity. The stage has been set to ' + stage;
        string proxy = 'http://staging-api.call-em-all.com/webservices/CEAAPI_v2.asmx?WSDL';

        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint('http://staging-api.call-em-all.com/webservices/CEAAPI_v2.asmx?WSDL');
        req.setHeader('Host', 'api.call-em-all.com');
        req.setHeader('Content-Type', 'text/xml; charset=utf-8');
        req.setHeader('SOAPAction', 'http://call-em-all.com/ExtCreateBroadcast');
        string bod = ''+username+''+pin+''+TTSText+''+TTSText+''+broadcast_name+''+broadcast_type+''+caller_ID+''+PhoneNumbers+''+phone_number_source+'';

        req.setbody(bod);

        Http http = new Http();
        HTTPResponse res = http.send(req);

        System.debug('These were the results: ' +res.getBody());
    }
}


And the trigger:
trigger Opportunity on Opportunity (before update){
    for(Opportunity o: trigger.new){
        if(yourcriteriahere!){
            Call_em.callMe(o.Name,o.StageName);
        }
    }
}


Explanations: I've kept the class as simple as possible for now. Ideally, you would probably not want to create a new broadcast every time the trigger was initiated. You would want to create your broadcast in advance and add the new number to it.
Note that the method is annotated with @future and callout=true. This is required as the trigger will make the callout asynchronously. The first part of the class is just setting up some variables. Looking at it, I don't think I used the proxy variable. My trigger will feed it two strings (yum); the Opportunity Name and the Opportunity Stage. I then create the new POST HTTPRequest, decalre the endpoint, and set up a few headers. Notice that my endpoint is set to their "staging" URL. I would recommend that this be set to a variable so that you could toggle between their staging and production environments relatively easily.

The trigger speaks for itself. You can use the "Call_em.callMe(o.Name,o.StageName)" line as an action for a button or even modify it to be used in a schedule Apex class.

Once you get this sample working, dig around in their API a little bit. You should be able to leverage existing broadcasts, modify lists, send text messages and so much more!

API Documentation: http://www.call-em-all.com/dev/docs.aspx

</end sales pitch> ...just kidding

Tuesday, October 18, 2011

Business Hours and Holidays!

The holidays are coming and do you know when your tasks are due?  There's an ongoing issue with Salesforce that I've inquired about throughout the years.  Although you can set business hours (even multiple profiles for hours) and holidays, these aren't taken into consideration when workflow actions are applied or due.

A few years ago, the answer to my inquiry was to research the IdeaExchange.  The idea already existed then and unfortunately is still just an idea today.

IdeaExchange Link:  http://success.salesforce.com/ideaView?c=09a30000000D9xtAAC&id=08730000000Bpq3AAC

What a shame!

Is there anything you can do?  Absolutely, but I hope you like Apex Triggers.

There is a BusinessHours Class that you can read about in the Apex Developer's Guide:  http://www.salesforce.com/us/developer/docs/apexcode/index.htm?businesshours

The first thing you want to do before you start playing around with that, though, is to set up your business hours by going to Setup --> Administration Setup --> Company Profile --> Business Hours

For my example, I'll have a default schedule of Monday through Friday, 8AM to 7PM.

I've also set up some holidays through Setup -->  Administration Setup --> Company Profile --> Holidays.  Don't forget to go back to your Business Hour schedule and add the holidays to it by clicking on the "Add/Remove" button.

Got that configured?  Now you're ready to give it a whirl.

Of course you'll want to work this into a trigger, but for demonstration purposes I've just created a test class and pulled in the system date/time (system.now()).

The VF Page:

<apex:page controller="test_business" >
    <apex:form >
        Current Date: {!oldDate}
            <br /><br />
        New (w/ GMT): {!newDateGMT}
    </apex:form>
</apex:page>

Explanation:  Just two simple getter methods from the test class.
  • oldDate is simply pulling in the current date/time using the system.now() method. 
  • newDateGMT is returning the adjusted date/time according to the line w/in that getter method

The Class:

public with sharing class test_business {
    public DateTime getoldDate(){
        DateTime oldDate = system.now();
    return oldDate;
    }

    public DateTime getnewDateGMT(){
        BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
        Datetime oldDate = system.now();
        Datetime newDate = BusinessHours.addGMT(bh.id, oldDate, 3 * 60 * 60 * 1000L);
        return newDate;
    }
}

Class Explanation: 
  • getoldDate just retrieves the system.new() method as explained above.  This is the full GMT value, not adjusted for your time zone.
  • getnewDateGMT has two main parts
  1. The query is creating a BusinessHours object named bh after retrieving the one I created earlier and set as the default.
  2. Where I declare the newDate Datetime, I'm taking advantage of the addGMT method in the businesshours class.  I need to feed to it the ID of a BusinessHours object, a starting date, and my increment (in milliseconds).  Broken down, that looks like this:
    1. 3 - # of hours
    2. 60 - 60 seconds in a minute
    3. 60 - 60 minutes in an hour
    4. 1000L - 1000 milliseconds in second

Monday, October 17, 2011

Summary Report Export: Too Many Details!!!

Say you're perusing a few reports you haven't seen since the dawn of your SF Org, thanks to the new Winter '12 report folder interface, and you come across an oldie but a goodie summary report.

"Awesome," you think as you quickly click on the "Export Details" button to work some Excel magic and show off your report's findings. Wait a second, that once dusty report's Excel file equivalent looks nothing like what you saw in your browser window. What's going on here?

The "Export Details" button does exactly that... it exports the details of the report; meaning every line that makes up your report will be rendered as a new line in your .xls or .csv. This is regardless of whether or not you have clicked on the "Show Details" or "Hide Details" button. Of course, you could rework the resulting spreadsheet and do the grouping yourself, but why would you do that?

Rather than eagerly clicking on the "Export Details button," take the "Printable View" button for a test drive. It will render your report again as an .xls file, but retain the grouping as you see it on your report.

If you want to see the details, click on the "Show Details" button prior to clicking on the "Printable View" button. This will show each line item as well as the summarized headers. If you don't want details, make sure that you've clicked on the "Hide Details" button.

In case you were wondering, this also works for Matrix reports!

Wednesday, October 12, 2011

Error: Invalid API Version... Come Again?

One thing that I love about Salesforce is the sneak peak that we get in our sandboxes prior to each new release. On occasion though, I've worked on something new in one of these developer preview sandboxes and wanted to deploy my code to production. Only to receive an "Invalid API Version" error message.

Right now, my production environment is Summer '11, but my sandbox is Winter '12. If I were to create a new Visualforce page in my production environment, the Salesforce API version would be version 22.0. If I do the same within my sandbox, the API version is 23.0. The dilemma, upon deployment, is trying to push version 23.0 into a platform that only supports up to version 22.0; hence the "Invalid API Version" error message. I've done this with pages, but I imagine it is quite possible to experience with classes, triggers, templates, etc.

How do you fix this? Wait for the update to be applied to your production environment. Just kidding...
Within Salesforce, you can go to "Setup" --> "Develop" --> "Pages" --> and click on your page's name. From there click on the "Edit" button and then on the "Version Settings" tab. Drop your version down to that which matches your production instance. Click on "Save" and try your deployment again.
From within the Force.com IDE/Eclipse, expand your project and browse to the page, class, trigger, whatever file you're having issues deploying. Below that file, you should see an identically named file, appended with -meta.xml... edit that. In the editor pane, you should see an xml file structure. You may need to click on the "Source" tab below. Look for the tags and replace the version number with that which matches your production instance. Save it down and try deployment again.

Example:
<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
  

<apiVersion>23.0</apiVersion>

<description>Default Force.com Change Password page</description> <label>ChangePassword</label> </ApexPage>

While that should fix your problem, keep in mind you are reducing the API version, some it is possible that if you are utilizing some of the new release's features - your file won't save after the API version number change and those features won't work.

Speaking of version numbers, one question you might have is whether or not you need to go through all of your old code to update the API Version after a new update comes along. Once Winter '12 comes out, am I going to update all of my classes, triggers, and pages to be version 23.0? No - you don't have to and you can leave them as is as Salesforce will maintain backwards compatibility. If you want to use some nifty new tags or features that didn't exist in that version set, you might have to change it down the road - but you'll know when you have to.