I am putting the finishing touches to an article on the updates to the Force.com for Facebook toolkit I blogged about a few weeks ago. There are still some wrapper classes to finish off before releasing the code/toolkit, but I thought it might be handy to share some code snippets on you work with the toolkit. Overall, the process is very similar to the current toolkit: you register your application, and then start working with the Graph API via a series of wrapper classes. 

Here is a sample of a test method using the FacebookLike object. You will note that I am passing in an optional test stub to allow me to write test code coverage above the 75% threshold even though I have callouts. (there are some great articles on strategies for testing callouts in your code on developer.force.com if you are interested)

 public static testmethod void test_Likes()
String stub = '{"data":[{"name":"Mindfulness","category":"Interest","id":"110882252269682"},'+
'{"name":"Jason Mraz","category":"Musicians","id":"6135205697"},'+
//clientid, facebook userid, optional teststub - set to null if not a test
FacebookLikes fbl = new FacebookLikes('136520473033312', 'qwall', stub);
System.assertEquals(fbl.allLikes.size(), 3);
System.assertEquals(fbl.allLikes.get(1).id, '6135205697');
System.assertEquals(fbl.allLikes.get(1).name, 'Jason Mraz');
System.assertEquals(fbl.allLikes.get(1).category, 'Musicians');

In addition to the wrapper classes, you can also leverage some of the Social components such as Like, Recommendation, and Recent Activities on your Force.com Sites page by dropping in a Visualforce component:

 More coming soon!

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS