Change and add fields in Force.com IDE

If you are using the latest Force.com IDE to develop s-controls or Apex code, you know how nice the latest upgrades are — for editing code, testing, and staying in sych with Salesforce.

I’ve just discovered something else really great — you can edit metadata for objects and fields in your Salesforce instance.  (It has to be a sandbox or developer instance, but you can then package and "deploy" your changes to a production instance.)

Have a custom object or a picklist in one instance and want to copy it to another?  Need to change a bunch of field names or picklist values?  You no longer need to package the items and install them from the appexchange, or go through all the pointing and clicking.  Instead, you make the changes in the object metadata XML files in Eclipse — you can use the XML design tools, or just edit the raw XML:

 

At first, I was getting a lot of errors when saving objects.  There is a bug, and I found the workaround here.  Basically, there is this file called package.xml — if you are adding an entirely new object (via the New menu), the Force.com IDE updates that file with your additions.  But if you just add custom fields, or if you copy and paste anything from one instance to another, it won’t be in package.xml, so you’ll get an error when saving or synchronizing to Salesforce. 

The trick is to open up package.xml, find or create the section that lists the type of thing you want to create, add the tags, save package.xml, and THEN save your new items.  For example, putting this code in package.xml lets me add the three custom fields shown in the Lead.object file above:

   
        Lead.Address_Type__c
        Lead.Birthdate__c
        Lead.Communication_Preference__c
        CustomField
   
Be sure to add the code to package.xml before EACH thing you add/paste and save, because Salesforce synchronizes package.xml when you save, taking out any entries that aren’t actually in your instance.

Apex in AppEx

At NPower, we’ve been making increasing use of Apex code to do some things we could not do before:

  • enforcing business rules across objects
  • updating records automatically across objects
  • rolling up data like membership renewal date and contact donation totals 
  • separating the web interface of s-controls from the code that actually modifies data

All great stuff!  And we love creating and testing Apex code (and s-controls) in Eclipse.  The latest release is really slick (more on that in another post).  But what we really wanted when this was all done was to give a consultant or a client a link where they could install this code into their own production instance of Salesforce.

Until this week, I thought the only way to install Apex code was to create a sandbox or developer account that exactly mirrors the account you want to install into, create and test all the code, and then deploy.  But I found out we can now package all this up into an AppExchange download.

I tried this out yesterday with a large package of apex, s-controls, custom fields, reports, and so on. The Apex code installed, tested, and deployed directly from the package link.

This will be a big timesaver for us — and in the long run, I hope it will make it possible for us to create powerful tools that clients can install with very little help from us.

Now all we need is the ability to package page layouts on standard objects.

S-Control for Filtering a Report

Some time ago, I had a client who needed an easy way for inexperienced users to filter a report, on a regular basis, based on several different criteria.  In Salesforce, anyone can filter a report like this, but it takes a couple dozen clicks and a bunch of typing.  I wrote a simple s-control that allowed users to filter the report in a really simple interface.

 

When the user selects values and then clicks Search, the Javascript code builds a long URL that tells Salesforce to open the report and apply all the selected filters - something like this:

https://na3.salesforce.com/00O50000001QCuS?pc2=00N50000001JsTx&pn2=eq&
pv2=American%20Sign%20Language&pc4=00N50000001JsUX&pn4=in&pv4=Immunizations&
pc5=00N50000001JvOE&pn5=in&pv5=North%20End& pc6=00N50000001JvNO&pn6=eq&pv6=1

I showed my s-control to Drew Piston at a Salesforce event last year, and it turns out he was hoping to do something similar for his group at the Bay Area Chapter of Red Cross.  This week, he posted a Jing screencast that shows his version of the s-control in action.

Thanks Drew! 

Apex Triggers Screencast

While reading Steve Anderson’s blog (http://gokubi.com), I was inspired to put up one of our screencasts. 

Anand was nice enough to put together a great screencast about creating a basic Apex trigger. This dives into some code but isn’t too technical that the average Salesforce admin can’t understand it. Take a look!

http://www.screencast.com/t/KZyKK0NXrXR

Nonprofits using Advanced S-Controls and Apex

I want to show you how a particular nonprofit is using Apex code: the Center for Employment Opportunities (http://www.ceoworks.org).  They demo’d their Salesforce configuration at the NYC Nonprofit User Group (run by Lisa Glass-Kornstein, just back from her honeymoon!).  They use Apex to do complicated business logic like cross-object verification and data transfers based on triggers.  I know Jessie Grenfell from CEO is going to update this presentation, but I figured I’d get it out there so people can see it.

Are you using S-controls or Apex in your organization?  What business process are you solving with these tools? 


By rob

Post Dreamforce ‘07 - Surfacing

My apologies for the spotty posting and test posts. Beth’s linking brought more subscribers than I anticipated during this soft launch.  I’ve been back from San Francisco almost a week now, but I feel like I’m just surfacing.  I was hoping to do a more formal launch of this blog at the conference - and post much more during the conference than I did - but I was having some technical difficulties with Wordpress…so there you have it.

A few DF roundups:

I plan on doing a broader announcement sometime soon. If you are reading this via RSS, please spread the word (and contact me if you are interested in blogging here about salesforce).