I’m going to Dreamforce

Dreamforce

After 6 years of doing Salesforce, I’m finally attending my first Dreamforce- the biggest software event in the world, where people gather from all over the world to share ideas, learn new skills, connect, and be inspired.

I have been fortunate enough to work for a company such as Davanti Consulting, a New Zealand premiere Salesforce Partner. They send people annually to attend Dreamforce but, they don’t just randomly select employees to send. There is a rigid set of requirements and anyone qualified needs to put up a case why they should be selected and what would the company gain by doing so. This was nerve racking as I have now to come up with a presentation that would stand out among the rest of my peers who are as qualified I am.

So how did I pull it off? For one, I was on top of recent news of Salesforce acquisitions of machine learning and AI companies so that kind of gave insights on what Dreamforce would be about this year. I’ve always been keen on exploring other technologies and having a play on them. Salesforce recently did restructuring on their product line and out came App Cloud, coming off from an engagement where I lead the mobile employee app using lightning and another client facing application on force.com. My pitch generally evolved around the idea that attending Dreamforce would upgrade my skills particularly on client facing apps and gain traction on IOT, get an insane amount inspiration and I’ll be bringing back the knowledge with a series of sessions. I got the nod from our senior team and choose me to go to Dreamforce. I’m just stoked as attending Dreamforce was on of my goals for the longest time.

Looking forward to do a series of blog post commencing the event. For now time to earn my Dreamforce badges via trailhead.

dreamforce-badge

Reference the External ID on Lookup

This post shows you how you can reference another object through it’s external id. This is useful if you do not know the Salesforce ID but know the external ID.

Example: You have an external field on the Account object with an API named myExternal_Id__c. You have an account record named “Burlington Textile of America” and let’s give the external ID a value of “X123”.

 

Issue is you want to create a contact record but do not know the account record id but know the external Id.

Check this snippet of apex code to accomplish this.

Account acc = new Account(myExternal_Id__c = ‘X123’);

Contact con = new Contact();

con.Account = acc;

con.LastName = ‘Pau’;

insert con;

The same concept is applicable for JSON files

{

“Account” : {“myExternal_Id__c” : “X123”},

“LastName” : “Pau”

}

 

Master-Detail: Field is not writable error on Apex

I came upon this error when I assigning the custom object to the master standard object.

Invoice__c inv = new Invoice__c();
inv.Account__c = accountId;
insert inv;

Then I get this error.

Field is not writable : Invoice__c.Account__c

The fix was actually easy. I just rewrote it to assign the master id on instantiating the child object.

Invoice__c inv = new Invoice__c(Account__c = accountId);
insert inv;

Hope somebody finds this useful.

Add row rerender on a list with input fields looses data

Having a list in your controller that is displayed as input fields either through pageblock or repeat and you need to add another row to the list via a button.  Chances are when you enter data on any input field on any row and you hit Add Row button that has a rerender attribute that makes the ajax call, the previous entered data will be lost as per code sample below.

public class MyController {
public list<myOject__c> objList {get;set;}
public MyController() {
objList = new List<myObject__c>();
}
public void addRow(){
myObject__c newObj = new myObject__c();
objList.add(newObj);
}
}
VF:
<apex:pageblock id=”myList”>
<apex:pageblockSection value=”{!objList}” var=”obj”>
<apex:column>
<apex:inputField value=”{!obj.Name” />
</apex:column>
</apex:pageBlockSection>
<apex:commandButton value=”Add Row” action=”{!addRow}” rerender=”myList”/>
</apex:pageblock>
The simple solution is to add the attribute immediate=”false” to the commandButton tag. This forces the data to be retained.

Parsing Instagram JSON on Apex

Last week I had a challenge of making a API callout to Instagram from Salesforce and then parse the returned JSON content and the mapped the values to become a record for a custom object. Basically each media post and comments becomes a record in Salesforce.

First off you can start by reading this article

According to http://www.json.org:

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. … JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.

To begin, what I have here is an API request for comments for a particular media or picture I have in Instagram.

Read the rest of this entry »