Sunday 22 February 2015

API vs Library vs Framework vs SDK vs Toolkit - the Burning Question




API It is used to interact with the System which you have made. For Example:  On the Click of Green Button on your phone, A Call Starts, the Key Pad is an Interface(as an API) which is used to interact with the internal system. In Software Terms, It is a method for external system to interact with the software.

Salesforce.com provides us with ability to create programmatic access to our organization's information using API's. Deciding which API to use depends upon the functionality which you would like to achieve and moreover the understanding which you possess about the ability of the respective API. As discussed on this link, you can judge yourself to use the API of your kind.

Library contains a pool of classes whose methods are exposed as API. Salesforce Library provides us with a vast number of classes which we call around to make our life easy. For Example : the System Class contained in the Library is has a number of live saving methods like that of System.debug.

Framework helps developer to build something new.It is underlying code which helps developer to build their own code.Talking in terms of Salesforce.com, We have the Rich GUI based Force.com Platform which does the same for us.A great example to this context would be ASP.net, which is nothing but a collection of libraries,compilers to develop Sites. 

Toolkit is a new abstraction layer over library. It often consumes library and allows ease of methods with less error for the developers. Salesforce provides us with delightful Google Data API Toolkit, Facebook Toolkit which makes life more easy.

SDK - Service Development KIT
It is an abstraction layer over the Interface. API can be a sub-set of SDK. It consists of consists of API, Documentations, Compilers, Framework, Sample Code, Utilities which saves time of Developer to create new code from scratch. 

If we want to use the functionality which we have made into other Software,  we can expose our APIs. If we want the other parties to develop / modify / fix / the existing system for their use we provide SDK. For Example: The Mobile SDK 3.0 provided by Salesforce. It provides the developers/companies to develop applications on the go for Mobile, providing methods and classes which make life easy and not worrying about the mobile coding paradigm. They applications developed over Mobile behave same as the other applications, they get regular updates, push notifications, support of ads etc.

Wednesday 21 January 2015

Dynamic SOQL Field Names in Query !


SObject row was retrieved via SOQL without querying the requested field

This might be a smaller error which you can easily address. But, there are challenges imposed when in an Query we need to add many fields to be retrieved. For Example:

Problem: 

Say, You are building a dynamic query in which you have to extract more than 30 fields in the query. Added problem is there are a couple of Objects for which dynamic query is created.

or 

You want to remove this [SObject row was retrieved via SOQL without querying the requested field] Error permanently from your code-life. 

Solution: 

Just copy & paste the code shown below in your utility method.




During creation of query when you require to access all field names of any object just call the sober static method by passing the API Name of the Object as parameters : 

string query = BuildQueryUtil.fieldNames('Contact') + 'FROM Contact WHERE Name != null LIMIT 100 '
List<Contact> extractedContacts = Database.Query(query);

This works as a charm & results:  

SELECT phone, jigsaw, mailinglatitude, otherstate, leadsource, lastactivitydate, createdbyid, otherphone, description, isdeleted, level__c, systemmodstamp, assistantphone, isemailbounced, otherstreet, languages__c, otheraddress, fax, hasoptedoutofemail, createddate, ownerid, hasoptedoutoffax, canallowportalselfreg, jigsawcontactid, lastvieweddate, lastcuupdatedate, credit_status__c, email, donotcall, othercity, lastmodifiedbyid, mailingstate, reportstoid, photourl, department, lastcurequestdate, lastname, otherlongitude, ispersonaccount, lastmodifieddate, id, mailinglongitude, mailingcountry, mobilephone, mailingaddress, title, lastreferenceddate, email_2_other_one__c, otherlatitude, emailbounceddate, name, birthdate, mailingstreet, homephone, accountid, emailbouncedreason, masterrecordid, otherpostalcode, mailingpostalcode, firstname, assistantname, othercountry, salutation, mailingcity FROM Contact WHERE Name != null LIMIT 100

You can also extend this into nested queries to get the field Names of the Child Records.

Note: This might not serve as a Best Practice as it increases the Heap Size {Heap Size have Governor Limit } & can degrade the performance. More, Do not use if you are building packages. Use it in specific cases when you need all fields and the size of the field names is lesser than 20,000.


Happy Coding!