Reid Carlberg

Connected Devices, salesforce.com & Other Adventures

Tag Archives: salesforce

My Next #DreamJob @Salesforce

0

It is not without some sadness that I write this post.

For the last five years, it has been my pleasure to dive deep into the Salesforce1 Platform community. I have shepherded the Salesforce1 Labs program, helped launch AppExchange Checkout, delivered the IoT Zone experience at Dreamforce 2013 and co-delivered it for Dreamforce 2014. I have met thousands of developers, admins and partners; diagnosed problems, challenges and opportunities; and talked with CEOs, CIOs and CTOs about their businesses. I have presented on a large number of topics at user groups and conferences around the world, and worked extensively with Salesforce’s uniquely awesome Sales Engineer, Account Executive, Customer Success, and Services teams.

And make no mistake: it has been my honor to work with a great crew of Developer Evangelists and an incredible Developer Relations team. They have been fantastic and inspirational co-workers. They have pushed me to be better and I have learned a ton from them in the process. I am incredibly grateful to have met them!

Yes, the last five years have been fantastic.

However, these words (penned by fellow Kenyon College grad Bill Watterson) have often bounced around in my head:

calvin-change

And so I have decided to embark on a new adventure.

Later this week I officially transition to the Salesforce Marketing Cloud where I will help manage a collection of products on the mobile team, including MobilePush. We have a great team working on these products, and a great crew of customers using them. It is a huge opportunity for Salesforce and I am very excited about the chance to shape it.

Best of all, I still get to work with the Salesforce developer community: one of the key outputs of my new team is a series of developer facing mobile SDKs (checkout the Github account).

These last few days have been more emotional for me than I predicted. My last regularly scheduled 1:1s with my team in particular — such a great crew!!

A big thank you to Salesforce for this new opportunity, and a big thank you to everyone I’ve worked with — in and out of Salesforce — over the last few years. Here’s to many more together!

Yes, this is change, but I’m not going far. You’ll still see me at Salesforce events and I’m still only an email or tweet away. Let’s definitely keep in touch, and if you have a question about Salesforce Marketing Cloud mobile apps, please reach out!

Mo Tester Octothorpe: Now with Lightning Process Builder & Lightning Connect Examples

1

I updated Mo Tester to include a couple more Lightning Examples. Install link and code are here.

It now includes the External Data Source Pat created for the Lightning Connect Tutorial. Select the “LAB Mo External Data” app to see the tabs.

Mo Tester also includes a Lightning Process Builder Example. It fires when you create a Mo Tester 1 record with a particular name, either “Chatter” or “Later”. “Chatter” posts immediately, “later” posts an hour later.

mo-tester-octothorpe

Experiment Faster with Lightning Components & Force.com (Mo Tester Update)

0

Update from 2015-03-06: Mo Tester Octothorpe

TL;DR: Updated Mo Tester, install link on Github Repo.

Back in the day I wrote a post called Experiment Faster on Force.com where I confessed to blatantly stealing an idea from Mr. Steve Molis himself.

It was SteveMo’s idea to have a dev org with a bunch of objects already built, objects with fields of every shape.  My add was to create a package out of it, so that other users could try things out more quickly than if they had to build everything themselves.

Hence: Mo Tester.  Mo Tester is lab equipment for your Developer Edition.  It gives you a pre-defined framework for messing around with many kinds of Force.com goodies, and now includes some basic Lightning Components for your enjoyment.

This update:

  • has an new Visualforce controller (which inspired a post on Refactoring Visualforce Controllers for Lightning Components)
  • includes a Mo Tester Lightning Tab suitable for immediate inclusion in your DE’s mobile navigation
  • demonstrates several Salesforce1 Lightning Component events including (drum roll) a SHOW TOASTER button.

Hopefully this update helps you go faster as you’re discovering what you can do on the platform.

Questions? Comments? Feedback? LMK!

@ReidCarlberg

Refactoring Visualforce Controllers for Lightning Components

1

You might remember Mo Tester, the package that helps you Experiment Faster on Force.com. I’m tweaking it for some Lightning Component stuff (spoiler alert) and ran into this.  (Posting to the Lightning Newbie Notes too.)

The following code won’t compile. You’ll get a handy Return type does not support AuraEnabled error because — wait for it — the @AuraEnabled annotation doesn’t support PageReference return types.

@AuraEnabled
public PageReference createMoTester1() {
    SmartFactory.FillAllFields = true;
    LAB_Mo_Tester_1__c t = (LAB_Mo_Tester_1__c) 
           SmartFactory.createSObject('LAB_Mo_Tester_1__c');
    insert t;
    return new PageReference('/'+t.id);
}

You need to refactor your Visualforce controller to have two methods, one for your existing code, one for your new Lightning Component.  Also, the @AuraEnabled method needs to be static.

public PageReference createMoTester1() {
    Id myMo = LAB_CreateDataHelper.getNewMoTester1Id();
    return new PageReference('/'+myMo);        
}    

@AuraEnabled
public static Id getNewMoTester1Id() {
    SmartFactory.FillAllFields = true;
    LAB_Mo_Tester_1__c t = (LAB_Mo_Tester_1__c) 
           SmartFactory.createSObject('LAB_Mo_Tester_1__c');
    insert t;  
    return t.id;                
}

Note that in this case, based on the way my test classes are structured, this didn’t affect my code coverage. It was 100% before, it’s 100% after.

Incidentally, not supporting PageReference return types is perfectly logical when you think about it.  PageReferences are a Visualforce thing after all.

Also note that, yes, I’m bewildered by my choice of method names here, too.  Also, the original package doesn’t seem to use this method.  And the test coverage in the package didn’t include coverage for the StandardController and StandardSetController dependent constructors. What was I thinking???

Looking at old (ish) code is fun.

Update 2/23/15 — I did use the button, on the list view.  I just didn’t inspect hard enough.  Phew & Sheesh!mo-tester-button-found

 

Also the method has to be static.  Whoops!

Salesforce Lightning Component Newbie Notes

1

Like a lot of you, I recently started down the path of learning Lightning Components. These are my notes and code snippets based on a series of questions I asked as I went through the docs and tutorials. I hope you find them useful.

Salesforce Lightning Component Newbie Notes

This is the first time I’ve used Jekyll and markdown to create a relatively extended blog post.  Pretty convenient!

Simple Salesforce Lightning Connect Example (External Objects)

13

Lightning Connect includes External Data Sources and External Objects.  You can try this in your free developer edition. There’s a nice blog that talks about setting up a more custom data service and covers a bit more about why this is super cool.  Andy Mahood also blogged about this recently, including more details on related lists and Chatter.

Lightning Connect is the new service from Salesforce that lets you bring OData content into your Salesforce org. I was curious how to test it, so I thought I’d share what I found.

Step 1: Locate Sample Data

OData is a protocol for exchanging .. er … data, so it makes sense that you could probably find some sample data to connect to. A bit of the old Google led me to this sample data page where you can click on a tab to see “V2” sources.

salesforce-sample-odata

When you click on the Northwind sample, you get a bunch of XML (hooray). You’ll want to copy the URL in your browser window at this point.

salesforce-sample-odata-xml

Step 2: Create a new External Data Source

Back in your free developer edition, navigate to Setup > Develop > External Data Sources, and fill in the form as shown in the image. In the Server URL, paste the .. er … server URL you just copied above.

salesforce-external-data-source-new

Important: once you click “Save” you then need to click the button that says “Validate and Sync” before you can move on.

salesfroce-external-data-validate-sync

Once that’s complete, you will be able to select the specific object you’re interested in. For this example, select “Categories” and click on “Sync”.

salesforce-external-data-select

After a moment, you will return to the external data source screen and your external objects related list will look like this — sweet!

salesforce-external-objects-related-list

Step 3: Create a Tab for the External Object

If you click on the “Categories” label in external objects related list, you’re going to see an object definition screen that looks shockingly familiar. Yes, it even includes a “Page Layout” section at the bottom.

salesforce-external-object-definition

Adding this to a tab is super easy. Navigate to Setup > Create > Tabs, and create a new tab for a custom object. That’s it!  Now you can easily navigate to particular records, work with list views, etc — all of the stuff you can easily do with custom objects.

salesforce-external-object-related-list

Step 4: Do a SOQL Query

If you’re like me, you are by now fairly curious about accessing the data in Apex and in a standard SOQL query. Head on over to Workbench. When you login, be sure to login using v32.0. Jump to SOQL queries, and select the “Categories__x” object.

workbench-SOQL

And in the .. er … category of least surprising thing ever, you can see it works!

workbench-soql-results

But what about Apex you say? Yes, also just that easy, as you can demonstrate for yourself using Workbench’s Apex Execute utility.

workbench-apex-execute

Pretty Sweet!

Give it a shot and let me know what you think. @ReidCarlberg

 

 

 

 

Control an Arduino with a Raspberry Pi Using Node.js and I2C

8

You might also find this post helpful: Read Data from Multiple Arduinos with a Raspberry Pi B+ using I2C and Node.js

As a software developer, I usually stay away from lower level communication protocols. My logic has historically been: they’re a lot of work, and my time is better spent higher up the stack.

A couple of weeks ago, after suffering through a variety of failures and uncertainty higher up the stack, I decided the only way out was to go at least a little deeper. So I bit the bullet and connected a Raspberry Pi to an Arduino using the I2C protocol, and then was able to control the Arduino using Node.js. This post covers how I did it.

Raspberry-Pi-Wild-Thumper.jpg

My use case was fairly simple.  I decided to drive a Wild Thumper using the Salesforce1 mobile app.  The Wild Thumper is controlled by an Arduino compatible board, aptly named the “Wild Thumper Controller“.  You might remember I had a couple of these with me at the Connected Device Lab this Dreamforce.  In order to communicate with Salesforce, it needs to have some kind of a gateway that can talk to the Internet using HTTPS, which is where the Raspberry Pi comes in.  If you have a different flavor or Arduino sitting around this should still work.

There are a lot of really great technical introductions to I2C (including — gasp — one from 2001), but you don’t really need them to get started.  Keep these two basic ideas in mind:

  • You’re going to work in a Master-Slave configuration.
  • You need to connect three pins.  SDA, SCL and Ground.

That’s it.

Step 1: Slave Configuration on the Arduino compatible Wild Thumper Board is pretty easy.  In fact, you can simply use the “Wire > Slave Receiver” sample code included with the IDE to get started (below). Load this in the Arduino IDE as is, send to your device and then start the serial monitor.  Put it aside.

// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop()
{
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

Step 2: Setting up the Raspberry Pi is a little more difficult, but it’s well documented.  If you are using a standard Raspbian distro, the I2C port is not yet enabled.  Adafruit has an excellent post on enabling the I2C port.  Follow those instructions, then c’mon back.

Step 3: Wire your Raspberry Pi and your Arduino together and make sure the RPi can see the Arduino.  Pinouts on the RPi are a little irritating.  I use the Pi Cobbler.  It gives you a handy, easy to read guide to which pins are where.  If you are connecting directly to the GPIO pins, be sure to consult a pinout digram.

Before you connect everything, your RPi should produce this when you use the i2cdetect command.

Raspberry-Pi-Before-Arduino.png

The basic configuration is really simple.  Master SDA pin to Slave SDA, Master SCL pin to Slave SCL, Master GND pin to Slave GND.  On the Wild Thumper Controller, SDA is A4, SCL is A5 and GND is any pin on the outside edge of the board.  And an Arduino Uno R3, there are special pins for I2C, above the AREF pin, clearly labeled on the back side of the board. In my case, the result looks like this (that’s the Wild Thumper Controller on the right, Pi Cobbler on the left):

Raspberry-Pi-Arduino-I2C-Wiring.jpg

After connected, your RPi should produce this (note that there is now a device on 4).

Raspberry-Pi-Arduino-After-I2C.png

Step 4: Install Node.js on to your Raspberry Pi using this simple link.  If you prefer to be a bit more hands on, you can follow these instructions.  If you prefer to be really hands on, you can install it by compiling from the source, but it will probably take > 2 hours and so far in my experience it’s no different.

Step 5: Install something that lets Node.js talk to the Raspberry Pi’s I2C system.  You should use the I2C library.  There are a couple of others out there, but this is easy and popular.  Now you should be able to do something like this:

var i2c = require('i2c');
var device1 = new i2c(0x18, {device: '/dev/i2c-1', debug: false});
device1.setAddress(0x4);
device1.writeByte(0x2, function(err) { console.log("error"); console.log(err); });

And see a “2” in the Arduino serial port monitor (like so).

Arduino-Serial-Monitor.png

There you have it — the basics of controlling an Arduino using a Raspberry Pi with Node.js and I2C. My original goal was to control the Wild Thumper via the Salesforce1 app.  I was able to accomplish that pretty easily.  Here’s my basic controller for the Thumper, and here’s the Node.js app running on the RPi.  I created a simple UI on the Salesforce1 mobile app (below)  that sends commands to the Thumper using the Streaming API and connects to Salesforce using the excellent nforce.

Salesforce1-Arduino.png

%d bloggers like this: