It the new year again and time for resolutions. I made a resolution about a year ago to learn ruby. If you are looking for something to learn this year I would recommend ruby and here’s why:
Salesforce.com bought Heroku for $220M
Salesforce.com has been pushing “Open. Social. Mobile” for quite some time.
Ruby is great for creating social and mobile apps with open source technologies.
Do you see a correlation here? There are big things ahead for Force.com developers using Heroku. Eventhough Heroku is a polyglot platform, it shines with ruby. If you have the time, add ruby to your toolbox.
I presented this topic today at an Appirio Continuing Education webinar and thought it might come in handy to other trying to learn ruby. In the video I build a small app that displays a list of accounts, the details for a selected account and then queries for accounts by keyword. I reference some links to help you get started with ruby and rails and I’ve added them after the video.
Yesterday Amazon announced Amazon DynamoDB, their Internet-scale NoSQL database service. Back in November we were fortunate enough at CloudSpokes to be invited to participate in a private beta for Amazon DynamoDB. We’ve since then had some time to “work it over” a bit and I have put together a demo application to show off some functionality. The code for the HomeController is below but you can find source for the entire applications at our GitHub repo for your forking convenience.
The API is very straight forward and easy to work with. If you’ve used other NoSQL databases then you should have no problem wrapping your head around Amazon DynamoDB. It has simple storage and query methods, allowing you to store and access data items with a flexible number of attributes using simple “Put” or “Get” web services APIs. Amazon DynamoDB provides a native API for HTTP and SDKs for Java, PHP and .NET. More are reportedly in the works.
What is Amazon DynamoDB and why would I want to use it?
Amazon DynamoDB is a fast, highly scalable, highly available, cost-effective non-relational database service that scales automatically without limits or administration. This service is tightly coupled with Amazon S3 andAmazon EC2, collectively providing the ability to store, process and query data sets in the cloud.
If you have massive amounts of highly transactional data then Amazon DynamoDB might be for you:
Store Social Graph data for processing
Storing GPS data for devices
Data storage for Hadoop processes
Record user activity logs
NFC processes
Recording clicks for A/B testing
Blazing Fast – Amazon DynamoDB runs on a new solid state disk (SSD) architecture for low-latency response times. Read latencies average less than 5 milliseconds, and write latencies average less than 10 milliseconds. We found our applications to be extremely responsive.
Hands Off Administration – Amazon DynamoDB is a fully managed service – no need to worry about hardware or software provisioning, setup and configuration, software patching, or partitioning data over multiple instances as you scale. For instance, when you create a table, you need to specify the request throughput you want for your table. In the background, Amazon DynamoDB handles the provisioning of resources to meet the requested throughput rate.
Auto Scaling – To continue with the “no administration” theme, Amazon DynamoDB can automatically scale machine resources in response to increases in database traffic without the need of client-side partitioning. Alternatively, you can also proactively manage performance with a few simple commands.
Security Baked In – Amazon DynamoDB is integrated with AWS Identity and Access Management (access keys and tokens) allowing you to provide access to defined users and groups, assign granular security credentials and user access, much more.
Centralized Monitoring – As with most everything in AWS-land, you can easily view metrics for your Amazon DynamoDB table in the AWS Management Console. You can also view your request throughput and latency for each API as well as resource consumption through Amazon CloudWatch.
API Overview
From a high level, Amazon DynamoDB API provides the following functionality:
Create a table
Delete a table
Request the current state of a table
Get a list of all of the tables for the current account
Put an item
Get one or more items by primary key
Update the attributes in a single item
Delete an item
Scan a table and optionally filter the items returned using comparison operators
Query for items using a range index and comparison operators
Increment or decrement a numeric value
Data Model
Amazon DynamoDB stores data in tables containing items with a collection of name-value pairs (attributes). Items (anaglous to a record) are managed by assigning each item a primary key value. Unlike traditional databases, the table is schemaless and only relies on the primary key. Items can contain combination of attributes. For example:
When creating a new table, you define the primary key and type of key to be used. Amazon DynamoDB supports a one name/value pair primary key (a hash primary key; string or number) or two name/value pair primary key (a hash-and-range primary key) for index values.
Note: the Query API is only available for hash-and-range primary key tables. If you are using a simple hash key, then you need to use the Scan API.
Data Types
Amazon DynamoDB supports two scalar data types (Number and String) and multi-valued types (String Set and Number Set). Everything is stored in Amazon DynamoDB as a UTF-8 string value. You designate the data as a Number, String, String Set, or Number Set in the request but there is no distinction between an int, long, float, etc. For example:
item.put(“member”, new AttributeValue().withS(“romin”));
item.put(“challenge”, new AttributeValue().withN(“1219″));
Amazon DynamoDB supports both Number Sets and String Sets:
Amazon DynamoDB uses JSON as the transport protocol. However, the JSON data is parsed and stored nativly on disk.
That’s a quick overview so make sure to check out the DynamoDB documentation for more details. The documentation is very well done and has clear instructions and code samples for Java, PHP and .Net. If you are into database performance, check out the details on provisioned throughput, data consistency, conditional operations, performance factors and more.
How to get started?
Sign up for a new AWS account (if you don’t already have one) and get your AWS Access Key ID and Secret Access Key from your account’s security section. Walk through their Getting Started Guide for samples. In your code, just add your credentials to the AWSDynamoDBClient and you are ready to start making requests. All of the API calls are pretty straightforward and work as you would expect them to.
Pricing is, again, pay as you go but Amazon DynamoDB is part of the AWS’s Free Usage Tier so check it out for more info.
Writing unit test in Salesforce is, in my opinion, a “black art”. There are so many workarounds and “techniques” that it makes the process extremely frustrating. The issue below makes me enjoy the process even less based upon the amount of time/money I spent wasting on it.
BTW, go vote on my idea to make Apex testing easier. You’ll thank me later.
I’ve seen a number of people on twitter recently comment that unit test coverage display different percentages when tests run in the browser vs. in Eclipse with “Run All Tests”. I just ran across this same issue and finally found the way to “work around” it.
I had an existing test class that I was updating and when I “Ran All Tests” from Eclipse I received a different result than when I “Ran All Tests” in my browser.
For some reason it looks like salesforce.com is caching the class and not re-running the actual test cases. When I edited the class, saved it and “Ran All Tests” again in the browser it finally displayed the same-ish results.
Chow Finder is a mobile application for services members to easily locate dining facilities, aka “chow halls”, on any military installation. It was inspired by my sons in the Army and Navy who are always looking for their next meal.
Play! has dependency management baked into it. This allows you to express your application’s external dependencies in a single dependencies.yml file. So if your app requires commons-lang or log4j, you can list them in your depencies.yml file and Play! will download them for you and place them in your lib directory.
So I’m making changes to my Play! demo app for salesforce.com and am trying to specify the Force.com Web Service Connector (WSC) in my dependencies.yml file. However, I think that I’m not referencing them correctly as the module is not being found in mavenscentral and downloaded. I’ve tried different combinations with the artifactId and groupId but nothing seems to work. Here’s my dependencies.yml:
require:
- play
- force-wsc -> force-wsc
When I run play dependencies –verbose in Terminal I get the following:
:::: WARNINGS
module not found: force-wsc#force-wsc;->
==== mavenCentral: tried
http://repo1.maven.org/maven2/force-wsc/force-wsc/->/force-wsc-->.pom
-- artifact force-wsc#force-wsc;->!force-wsc.jar:
http://repo1.maven.org/maven2/force-wsc/force-wsc/->/force-wsc-->.jar
::::::::::::::::::::::::::::::::::::::::::::::
:: UNRESOLVED DEPENDENCIES ::
::::::::::::::::::::::::::::::::::::::::::::::
:: force-wsc#force-wsc;->: not found
::::::::::::::::::::::::::::::::::::::::::::::
Any help with this issue would be greatly appreciated!
Update!!
I worked with @jesperfj this morning and he pointed me in the right direction. I needed to include the groupId and version as well. The correct syntax looks like:
require:
- play
- com.force.api -> force-wsc 22.0.0
I’ve been using Play! since Dreamforce 11 when Heroku announced support for it and I have to say that I’m addicted to it. If you love Java (and who doesn’t) but hate developing Java applications with all of the crap that goes along with it (Maven, XML config files, deployments, etc.) then the Play! framework my just be your savior.
I did a small demo with salesforce.com integration with Heroku and Play! if you would like some sample code or to run it for yourself.
Here’s what I like the most about Play!: it makes me productive. The development style is similar to Rails and I can simply get stuff done. I don’t have to save my Java code, restart Tomcat, wait for Hibernate to fire up and then see if my code runs as expected. With Play! I make my modifications, hit refresh in the browser and presto! my new app is either up and running or there is a nice, pretty error message.
Running Play! is a breeze. The framework comes bundled with Jetty so I don’t have to install and maintain Tomcat locally and when I’m ready to put the app into production, I just push it to Heroku and they take care of the rest.
If you want a great intro to Play! and why you might to use it, check out the first 10 minutes of this video from Dreamforce 11, “Introducing Play! Framework: Painless Java and Scala Web Applications”. The reset of the preso gets into actually building an app so if you want to see some code, feel free to continue watching.
The new System Log (aka Apex CSI) is a cool new part of Winter 12 that significantly reduces the pain of debugging Force.com applications. This is a great video from Dreamforce 11 showing you how to use the new console to debug code, set “breakpoints” and examine heap variables and more.
I’m working on some of the Apex REST services for our CloudSpokes org and needed some code to fetch field level metadata using Apex Describe. I poked around and realized that there isn’t really much out there. So I decided to write something up and hopefully people find it useful or instructional. Perhaps it should be part of apex-lang?
If you’ve ever worked with Apex Describe before you’ll quickly realize that it’s not the easiest thing to work with. You’ll want to take a peek at the docs. Don’t get me wrong, it’s power, fast and very handy. But it is rather confusing and cumbersome to work with at first. So I wanted some code that returns the metadata for specific fields in an object so that I could look at field types and lengths and perform “stuff” accordingly.
So here’s what I can up with. You pass the method the DescribeFieldResult for an object and a collection of fields that you want metadata for. The method returns a map where the field names are the keys and the values contain the metadata for the corresponding field. It looks pretty hard but that’s the great thing about utility methods, they encapsulate and hide the complexity of the implementation.
public static Map<String, Schema.DescribeFieldResult> getFieldMetaData(
Schema.DescribeSObjectResult dsor, Set<String> fields) {
// the map to be returned with the final data
Map<String,Schema.DescribeFieldResult> finalMap =
new Map<String, Schema.DescribeFieldResult>();
// map of all fields in the object
Map<String, Schema.SObjectField> objectFields = dsor.fields.getMap();
// iterate over the requested fields and get the describe info for each one.
// add it to a map with field name as key
for(String field : fields){
// skip fields that are not part of the object
if (objectFields.containsKey(field)) {
Schema.DescribeFieldResult dr = objectFields.get(field).getDescribe();
// add the results to the map to be returned
finalMap.put(field, dr);
}
}
return finalMap;
}
So now in my code I can call this static method in my Utils class and access the field metadata easily by fetching it from the map by it’s field name:
1
2
3
4
5
6
7
8
9
10
11
12
// field to return -- skips fields not actually part of the sobject
Set<String> fields = new Set<String>{'name','annualrevenue','BADFIELD'};
Map<String, Schema.DescribeFieldResult> finalMap =
Utils.getFieldMetaData(Account.getSObjectType().getDescribe(), fields);
// only print out the 'good' fields
for (String field : new Set<String>{'name','annualrevenue'}) {
System.debug(finalMap.get(field).getName()); // field name
System.debug(finalMap.get(field).getType()); // field type
System.debug(finalMap.get(field).getLength()); // field length
}
At Dreamforce a couple of weeks ago, Heroku announced the public beta for the Play! Framework on their cedar stack. So if you love Java but hate the pain associated with developing web apps, then the Play Framework is for you. It’s essentially a Ruby on Rails framework for Java. It makes Java development fun again!
Once again, this is a demo Java app running on Heroku using the Play! Framework. It uses the Force.com Web Service Connector (WSC) and the Partner jar to connect to a DE salesforce.com org. It uses the web services API to query for records, retrieve records to display, create new records and update existing ones. It should be good fodder for anyone wanting to start out with Play! and Force.com.
All of the code for this app is at github so fork awey. I’ve pulled out some of the more important parts of the app for a quick peek. There’s also an overview of one of the important classes to give you something to look at.
app/controllers/Account.java
The account controller contains all of the business logic for integration with Force.com and then packages up the returns for the views.
Abstract: As more and more applications move to the Cloud, Force.com integration is no longer just about connecting with on-premise systems and databases. You now also need to effectively connect with other cloud platforms. This session will show you how to integrate your Force.com application with other cloud platforms such as Amazon’s S3 storage, Google App Engine, and Microsoft Azure. The session will feature demos and code walkthroughs of the various cloud integrations.
I'm a Senior Technical Consultant at Appirio specializing in cloud-based applications using Salesforce.com, Google App Engine and VMware.
You should be a foster and/or adoptive parent. I'm both and it's fun!! Ask me how.
Buy My Books!
By Jeff Douglas & Wes Nolte
By Jeff Douglas &Kyle Roche
Favorite Quotes
"Any sufficiently advanced technology is indistinguishable from magic."
"Those who say it cannot be done should not interrupt the person doing it."