MK Partners Tips

Converting Strings to Integers with Apex

For one of our projects, we need to pass an integer to a function. Unfortunately, the integer is stored in a text field that is manually populated by the user. This means that it’s possible that some letters or other characters get put in the field in addition to the number we’re interested in. We know that you can do this with a regular expression but that’s kinda complex and above the heads of most of our readers. So here’s a simple way to do it via Apex that everyone should be able to follow:

Set<String> validChars = new Set<String>{'0','1','2','3','4','5','6','7','8','9'};
String mixedText = '123xyz';
String numbersOnly = '';
for (Integer i=0; i<mixedText.length(); i++)
{
    if ( validChars.contains( mixedText.substring(i,i+1)) )
    {
        numbersOnly += mixedText.substring(i,i+1);
    }
}

Report Folders to avoid

Here’s a quick tip:

The Force.com IDE allows you to deploy reports from one salesforce.com org to another. This is very useful if you’re a consultant like us, but also if you test changes in your sandbox before putting them into production. When it comes to Reports, you can only migrate reports from custom folders. This means you can NOT deploy reports that are stored in the Unfiled Public Reports or My Custom Reports folders.

Besides deploying reports, you can also modify reports, but it might just be easier to do it from within salesforce.com. One additional benefit to working with Reports this way is that you can index these files in GoogleDesktop or any other desktop search engine and then find which Reports reference a specific field or value before making a change. This is really useful when you have filters on RecordType names and want to change these names to fit a new naming convention.

So many DML rows, so few DML statements

Let me start by apologizing for the uber-geeky title to this post. We debated between other titles like Apex to the Future, and 100 rows of DML on the wall, but opted for one that would yield higher rankings in a search.

Lately, we’ve been getting a lot of Too Many DML Rows errors from existing code that used to work just fine. This is due to a recent change in the Apex Governor Limits. You can now only process 100 records via a DML statement per triggered record (Note that is 100 records total, not 100 per DML statement). In english, that means if you have a trigger that updates all Contacts on an Account when that Account is edited, you’ll get an error if there are more than 100 Contacts on that Account. This is a huge issue for some of us who have code that performs mass updates on records.

The good news is that there already is a documented solution that you can use to get around this. The @future annotation on an apex method has higher governor limits and we’ve found it to be a fairly simple process to update methods to use it. Start by adding the @future annotation to the line just before your method in your Apex Class. Then be sure to add the static annotation to your method. If your method only receives parameters that are primitive such as Ids, Strings, Integers, etc. then you may be done. If your method receives sObjects like Contacts, Accounts, etc, then you have to change them to receive Ids instead. Then, add a line to query for the records with those Ids. See the example below for more details.

The result is you get to update up to 10,000 records but the update occurs asynchronously, not immediately, so users expecting to see a change on the screen may get confused. Essentially you are just treating apex methods as asynchronous web services that are run on the salesforce servers. Now, we only wish we could schedule when in the future we want this method to run. When that feature arrives, maybe I’ll get to title the post Apex to the Future Part II

Old Method which will break if more than 100 contacts are being updated

public void updateContactOwner(Account[] accs){
Map<Id,Account> accountMap = new Map<Id,Account>();
for (Account a : accs ) {
accountMap.put(a.Id,a);
}
List<Contact> contactUpdates = new List<Contact>();
for ( Contact c :[Select Id, AccountId from Contact where AccountId in : accountMap.keySet()] ){
c.OwnerId = accountMap.get(c.AccountId).OwnerId;
contactUpdates.add(c);
}
if ( contactUpdates.size() > 0 ) {
update contactUpdates;
}
}

New Method which will update up to 10,000 contacts (although lists are limited to 1000 records, so some additional code is needed to get it to work on 10,000 records)

@future
public static void updateContactOwner(Id[] accIds) {
Map<Id,Account> accountMap = new Map<Id,Account>([Select Id, OwnerId from Account where Id in :accIds]);

List contactUpdates = new List();
for ( Contact c : [Select Id, AccountId from Contact where AccountId in : accountMap.keySet()] )
{
c.OwnerId = accountMap.get(c.AccountId).OwnerId;
contactUpdates.add(c);
}
if ( contactUpdates.size() > 0 )
{
update contactUpdates;
}
}

Which Edition of salesforce.com is Right for Me?

Which Edition of salesforce.com is Right for Me?

Your organization has taken the important step of signing up for salesforce.com, but to make sure you get the most out of your license, it’s important to determine which edition of salesforce.com is right for you.

Salesforce.com offers two basic choices for Nonprofit organizations, – standard Salesforce CRM (commonly used for the commercial sector), and the Salesforce CRM + Nonprofit Starter Pack. Both enterprise-level editions offer free 30-day trials and include Salesforce.com’s award-winning customer relationship management tools as a base from which to configure salesforce.com to fit your organization’s intrinsic needs.

The first choice, the “generic” salesforce.com template is seen as salesforce.com “out of the box”. This edition is generally oriented toward the business world but can be extended to fit any required non profit business process. In some cases the standard Salesforce CRM might be the right fit for your organization. The standard commercial Salesforce CRM doesn’t provide the same default functionality that a nonprofit may need (for example the ability to manage households), but it is still full-featured and can be a great starting point for your organization.

However, it’s been the experience of MK Partners that the addition of the Nonprofit Starter Pack takes away much of the initial trepidation of signing up for salesforce.com because it was built with the common core needs of the nonprofit sector in mind. By choosing this edition, nonprofit organizations can realize significant savings in customizing the application to meet their needs than they would if starting from a standard commercial version of Salesforce. This edition provides tools to help manage your organizations campaigns, leads, donations and contacts. Here, some of the names have been changed (An Opportunity is called a Donation, and a an Account is called an Organization, for example). This edition easily allows you to:

  • Manage donors and fundraising programs
  • Track affiliations
  • Manage a wide range of constituents in one place including donors, volunteers, board members, and more

The Salesforce CRM + Nonprofit Starter Pack

Imagine the complete power of Salesforce CRM (Customer Relationship Management) used everyday by thousands of for-profits, but with added functionality specifically for nonprofits to better track donors, donations, and fundraising programs. The Salesforce CRM + Nonprofit Starter Pack uses all of the power of standard Salesforce CRM and adds a base set of functionality unique to the nonprofit sector.

All the Benefits of Salesforce CRM

Because the Nonprofit Starter Pack is built on the salesforce.com platform (Force.com), nonprofits can also take advantage of all the powerful Salesforce CRM features.

  • Software as a service means no hardware or software to install or maintain
  • Award-winning ease of use that drives end-user adoption and compliance
  • Apply work-flow triggers to automatically generate tasks for volunteers or board members
  • Create standardized templates for consistent, professional responses to queries that can still be personalized by the sender
  • Control access to sensitive data by creating user hierarchies to protect confidential information
  • Get instant insight and analysis with powerful dashboards and reports to quickly analyze and
    understand your constituent behaviors
  • Point-and-click customization to meet your organization’s specific needs
  • The flexible Force.com platform to meet even the most extensive customization and integration

The Nonprofit Edition was recently re-developed by the Salesforce Foundation and MK Partners to further meet the specific needs of non profits, and the roughly 400 organizations who sign up forsalesforce.com every week. While not all nonprofits operate in the same way, the template tries to address common core functionality that is traditionally found in the nonprofit rather than commercial sector.

Since its first release in 2006, the nonprofit edition has received important and exciting improvements. At the core, the application remains simple, by providing a rudimentary set of contact management and fundraising type functionality. However, it’s still defined in such a way that it can have multiple other nonprofit solutions added on to it via the AppExchange, including many solutions offered by MK Partners.

Features and Enhancements of the Nonprofit Edition

In addition to providing essential, built-in salesforce.com functionality, major features of the nonprofit edition include:

  • Sophisticated APEX code for automation, enabling customers to decide how they want to relate contacts and accounts.
  • New functionality such as Organization Affiliations and Contact Relationships.
  • Donation automation – built native to salesforce.com!
  • Single donation tracking capabilities
  • A converter to migrate existing users of the original nonprofit template over to the new one

Major enhancements:

  • Contact-to-Contact relationship tracking
  • Affiliation tracking
  • Fully automated capabilities for tracking individual people (constituents), the B-to-C model
  • Reduces the amount of clicks it takes to enter a new individual and maintain that data.

Benefits:

  • Bring higher levels of professionalism and shared communication to your organization.
  • Improve interactions with donors, volunteers, and supporters and encourage repeat donations.
  • Analyze your organizations initiatives from fundraising campaigns to program impact.

You can’t go wrong

With either template that you choose as starting point, there may be be a number of things to undo and change. For everything you like, there may be some things you don’t. One of the many benefits of salesforce.com is that it is configurable and extend-able to specifically fit any business process for any given organization; this is one of the hallmarks of salesforce.com technology. Whichever edition you choose, you have the powerful force.com AppExchange at your fingertips and customizable database with complete functionality.

Have further questions? The experts at MK Partners offer complimentary salesforce.com support for non profit organizations. Visit us online at mkpartners.com, or email us at support@mkpartners.com

Sign up for a free trial for either edition here:

Read the Product Donation FAQ

Watch MK Partners CEO and Nonprofit Starter Pack lead, Matt Kaufman’s webinar here for an exciting demonstration

 

Choose a Trial Salesforce CRM Salesforce CRM plus Nonprofit Starter Pack
1. Why should I choose this one? Salesforce.com’s award winning commercial CRM (customer relationship management).
  • Manage donors and fundraising programs
  • Track affiliations
  • Manage a wide range of constituents in one place including donors, volunteers, board members, and more.
2. Get more details Salesforce Standard Edition Data Sheet Salesforce CRM plus Nonprofit Starter Pack Data Sheet
3. Make a choice Sign me up for a trial of Salesforce CRM Sign me up for a trial of Salesforce CRM plus Nonprofit Starter Pack

reference: salesforce.com Foundation

My new best friend

I’d like to introduce you all to my new best friend. He saves me so much time when needing to get past page layout issues, he’s extremely fast at making little data fixes and he’s amazing at debugging code. I like to call him Sy, but his full name System Log and he’s available to you at the top of your salesforce.com screens.

Here’s an example of how the System Log just saved me some time:
A client asked us to load some test data into their sandbox, but when we loaded the data, we didn’t set the owner, so all the data was owned by our user. Normally to fix this, we would open excel, login with the Excel Connector, query the table, update the rows in Excel and the use the connector’s update function. (We could also use the data loader, but for simple stuff like this, the Excel Connector is often faster.) It’s really not complex or that time-consuming, but opening up Excel always seems like a chore, and dealing with security tokens is a pain. I was already logged into their org in Firefox, why should I have to login again! So, instead, I opened up the System Log, typed in the below apex code and executed it. Instant fix!

List cons = [Select Id from contact where OwnerId != 'INSERT CORRECT ID' limit 999];
for (contact c : cons)
{
c.OwnerId = 'INSERT CORRECT ID';
}
update cons;

Please note that we don’t recommend doing this in your production org as you could ruin a lot of data very quickly. But, there are so many times where we need to just make a minor update like this, or create a new record without filling out fields required by the page layout when this functionality is a huge time saver.

The System Log is even better when trying to figure out why Apex code is not doing what you want it to. Just open it up and take an action which will trigger the code and the System Log will show you everything that is going on behind the scenes. You may want to adjust the Log Level to a level closer to Finest to see more information.

For those of you that work in Eclipse a lot, you can use the System Log there too. It’s available from the Execute Anonymous view. It saved me so much time today that I was able to write this post!

Polishing Chrome

I’m sure many of you have already downloaded the new browser Google Chrome. The word on the street is that salesforce.com is lightning fast while using Chrome. Our informal testing verifies this too, especially with s-Controls. Power Users and Admins greatly benefit from the speed improvement. Developers, however, are probably missing several handy Add-Ons used in Firefox (ie Web Developer, Firebug, etc). Well, I don’t know if this is documented yet, but I did find some developer tools in Chrome by clicking on the Control the Current Page icon and then selecting the Developer menu option (see image below). These tools seem to slow down browsing, but could come in handy. Enjoy!

Chrome Developer Tools

Automating Support Requests

If you subscribe to our blog then you probably know that we have played a lot with Salesforce’s Email Service functionality. It’s been on our Remember the Milk task list for quite some time now, but finally this week we have converted our support email from a distribution list to a Salesforce Email Service.

This change should increase the number of support requests that actually get logged in Salesforce and we expect it to yield the following benefits:

  1. Better distribute the workload across all team members
  2. Reduce the number of emails in our inboxes
  3. Improve overall response time to customers
  4. Improve accuracy of reports on Cases
  5. Increase the number of requests logged on support contracts

We’re very excited about this enhancement and expect to see a great ROI. It actually only took under an hour to roll out, thanks to our previous time investment in playing with the Email Services feature. The only downside to using it so far has been the inability to notify members of our Case Queue via Assignment Rules and respond to the customer via Auto-Response Rules. Fortunately, we have workflow to handle that.

Testing Web-to-Case/Lead in Sandbox

Recently we created a rather complex Web-to-Case process for a client that involved sending out via email Web-to-Case forms that contained hidden fields which were used to assist processing by Apex code upon submission. Other than an issue with Outlook 2007 not rendering forms, the process worked out amazingly.

During testing, we ran into a minor design flaw in Salesforce. When you generate Web-to-Case/Lead html in Sandbox, the URL provided in the code is test.salesforce.com. In reality it should be tappx.salesforce.com or csx.salesforce.com (replacing x with the actual number of your server). It’s a minor oversight, but when testing out complex processes, it’s important to test every aspect in sandbox before deploying to production.

Special thanks to Pritzl for posting about this on the discussion boards.

Standard Objects and the curse of the MetaData API

Some of you may be familiar with a great tool called Snapshot by Dreamfactory. This tool allows you to backup your Salesforce schema, compare schema across two orgs, and push changes from one org to another. It’s very useful if you have a strict deployment procedures and test things out in a sandbox before going live in production.

I’ve always wondered how Snapshot was able to make changes not only to Custom Objects but also to Standard objects. The Force.com IDE for Eclipse allows you to make changes to Custom Objects, but it doesn’t seem to allow you to make changes to Standard Objects. This is a real bummer because it means you have to manually recreate changes that you want to move from sandbox to production. On big projects, that can mean hours of extra work!

Well, good news, a post by JonP on the Force.com discussion boards reveals the secret to accessing Standard Objects via Eclipse. Check out Salesforce on Rails to see a cleaner version of the instructions. Special thanks to Scott over at Arrowpointe for pointing this out to us.

So what does this mean for you? Well, if you’re a developer, it means you can easily move configuration from one org to another with drag and drop or cut and paste. You can also easily create many fields at once without having to click hundreds of times in the UI. If you’re an Admin, you can use this functionality to backup and restore your configuration. If you’re a sales engineer, you can easily switch your configuration to suit different demos. Everyone who deals with configuration can benefit, so what are you waiting for?

Custom Views on the Home Tab

One of our clients uses Salesforce to manage their call center. They really wanted a way to display their “Open Cases” view on the Home Tab. In the past, we’ve accomplished this by recreating the view in an s-Control. The problem with that is changes made to the fields displayed in the view on the Cases tab would not be reflected in the s-Control, so it’s not ideal for a dynamic organization.

The consultants at MK Partners put their heads together and came up with a simple yet dynamic solution. We leveraged a Custom HTML Component, an iFrame, and the Console functionality already in Salesforce to allow you to display an existing custom view on the Home Tab. Here’s how we did it:

1. Enable the Console Setup | Customize | Console
2. Create a new Console Layout
3. Add the object whose Custom View you want to use to your new Console Layout
4. Edit your Console Layout Assignment and make sure all your profiles have access to your Console Layout
5. Go to the Console Tab
6. Select the Object and then View you want to add to your Home Tab
7. Right-click anywhere in your View and select This Frame | Show Only This Frame*
8. Copy the URL for the Frame
9. Create a new Home Page Component Setup | Customize | Home | Home Page Component
10. Name it, select the HTML Area type, and click Next
11. Check the Show HTML checkbo
12. Paste the following into the box, replacing [INSERT URL HERE] with the URL from step 8:
<IFRAME src=”[INSERT URL HERE]” frameBorder=0 width=”100%” height=”204″></IFRAME>

13. Save your Component and add it to your Home Page Layout
* This function is available in Firefox

Here’s what it looks like:
Custom View on Home Tab

Some Tips:

* Working with iFrames in HTML components is a pain because you can’t edit them
(the iFrame gets rendered instead of the code being displayed) you’ll
have to delete it and recreate it if you want to make any changes.
* Hyperlinks for fields in the Custom View will open in the iFrame unless you create Formula Fields with the “_top” attribute.