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!

Wednesday, 2 July 2014

Taking on Salesforce Advanced Developer Certification [DEV 501] - Part 1 - the MCQ

After a long wait ! I am here with my experience on Salesforce Advanced Developer Certification [DEV 501]. 

Which statement is true about Visualforce syntax? Choose 2 answers

a. The <apex:controller> tag must be used to declare the page controller
b. Standard component attribute must be overridden using <apex:attribute>
c. Component attribute values must be surrounded by double quotes
d. A Visualforce page must start with the <apex:page> tag

You see, thats one of the most hardest question which I've got on DEV 501 MCQ. So, this must have boosted the confidence in you for the exam. 

First of all if you are in Salesforce & unaware of this examination, then I consider you to read the basics outlet over this Salesforce Link.

DEV 501 is considered to be one of the most toughest and important exam in Salesforce Certifications but for me DEV 501 [MCQ] was the easiest of the Certifications which I've done, the reason being my touch to Salesforce Development. 

Remember, You do not have to be an expert coder for this exam and you need to hold your nerves if you are a breed of intermediate developer or higher race.If you are a 
developer with the Developer Certification [DEV 401] and you have kept your hands dirty into Apex and Visualforce for about 4-5 mid level descent project then you may be a happy candid to appear for the exam. 

There are certain points conceptually and then technically which you need to cover up as a homework before going into the Certification. 

1. Do not jump into DEV 501 soon as you clear DEV 401, we are humans not Superman ! With time everything will come to you, Give some time to the Time. 
2. I know this one will hurt you bad but yes Reading the complete Apex Developer Guide & Visualforce Developer Guide would confirm that you are going to bring the certification to your email box. 
3. The Magical Training Videos - I have never been a fan of Training Videos before DEV 501 MCQ, but I would say that these are the real dumps which you can look for. If you do not have access to the videos, grab the course DEV 501 book. Just to make you more excited on this, almost every slide you go through in Salesforce DEV 501 Training Video will be a question in the certification exam. Consider this as Dumps as I did. 

4. After Registration, Do not worry ! Hold your nerves in the Paper, Trust me it is easier than DEV 401 if you are aware of the basic Apex constructs and Yeah ! do express your feelings loudly when you are clear. 

Technically, the following topics I find very important to study, but certainly of no use if you have watched the Training Salesforce Videos. 

Order of Execution
Apex Add Error Messge 
Salesforce Set Controller Basics 
SOQL statement [Remember ID is extracted by default, when you fire a query]
Apex Action Methods 
Debug Logs 
Custom Components Basics 
Migration Tool Basics
Types of Sandbox 
Test Class and their Limits Bascis 
Dynamic Apex Defitions 
Standard Controller Class & Custom Controller Class 
Visualforce Templates [this screwed me up.]
Email Services [the most logical and standard question which I came across]


The questions are  straight forward. Just as DEV 401 checks whether you know the Salesforce UI basics or not and do not confirms if you are an expert into it the same way DEV 501 is to confirm that you have done coding and not to check that you were the best coder in the town. 

Go for the paper ! Hold Your nerves ! Remember many humans have cleared this and this paper is designed by humans and so you are ! :) 
Do let me know if I can help or in any way I have helped you through this blog. I will be happy ! :) 

I am waiting for the assignment and sooner will share the experience over it as well. 

what if DEV 501 cleared ? find the Salesforce DEV 502 Course - Integration cannot be explained better and beautiful than that .. !! Sooner will share some good insight for it. 


Intermediate Developers & Cross Trained Salesforce Persons stay connected, I have my own book on Apex Design Patterns for you coming very soon a guide to make you confident enough to make you experienced !! 

Also , 

Packt is celebrating 10 years of success with over 2000 Titles in its Library. To celebrate this huge milestone, Packt is offering all of its eBooks and Videos at just $10 each. This campaign is specifically aimed towards thanking all our customers for their support and opening up our comprehensive range of titles just for $10 each. It covers every title and customers can stock up on as many copies as they like until July 5th.

Stay Tuned 
Happy DEV 501 ! Happy coding ! 
Salesforce-um-Bhavah !! 

Monday, 7 October 2013

Quick Fix :- How to build the URL to launch an Email template via Standard Screening



Case Study:

How to Create an email template that will Auto Fill the account, and primary contact when selected from the Send Email from the Opportunity Activity History panel.

Clicking on Send Email from there gives a blank window to send email from - How to fill them with information from the record which they are coming from

Solution :-

One click java-script to Send an email using standard emailing screen. See below :-

location.replace('/email/author/emailauthor.jsp?retURL=/{!Account.Id}&p24=<To Email Address>&template_id=<email template id>&p3_lkid={!Account.Id}&p3={!Account.Name}&p26=<from email address>&p5=&save=0');

Let us quickly analyze the URL Parameters :-

p2_lkid = it is "Email TO" Field Code , associated only with Contact ID of Contact Standard Object, populares the Contact in To Field of Email.

rtype = record type 001 means Account and so on

p3_lkid = whatId ( hidden lookup field) it is must if the merge fields are there in template

p24 = additional email to be added as addional

retURL = returning URL

p5 = stops adding more BCC

p26 = to change the domain from which you are sending

template_id - Email Template Id, It can have merge fields.

save = 0, means send the email automatically and return to retURL ,( leave it if you just need to see the screen with populated fields)

The aforementioned fields are standard fields provided from Salesforce side. These arent customizable but you can specify values for this as per your need and requirements. You can give merge fields values over there and that may help.

Monday, 16 September 2013

Crunch Code Clear Field using JavaScript on Visualforce Page

Simple Code Crunch to Clear Fields , clicking a Link.


A smiling code which takes the Id of the Field which you want to clear and clears it with the event.. Hope you like it.


<apex:page standardController="Contact" id="page">
    <apex:form id="frm">
        <apex:pageblock id="pblck">
            <apex:pageblockSection id="pbSectn" >
                <apex:pageblockSectionItem id="pbSitemLookup">
                    <apex:inputField id="accountLookup" value="{!Contact.AccountId}"/>
                </apex:pageblockSectionItem>
               
                <apex:pageblockSectionItem id="pbSitemLastName">
                    <apex:inputField id="contactLastname" value="{!Contact.LastName}"/>
                </apex:pageblockSectionItem>
               
                <apex:pageblockSectionItem id="pbSitemLink">
                    <b><a href="#" onClick="clearValue()" > Clear </a> </b>
                </apex:pageblockSectionItem>
            </apex:pageblockSection>
        </apex:pageblock>
       
        <p> <apex:commandButton action="{!Save}" value="Save" id="cmdSave"/> </p>
    </apex:form>
   
    <script>
    function clearValue()
    {
    document.getElementById('{!$Component.page:frm:pblck:pbSectn:pbSitemLookup:accountLookup}').value = '';
    document.getElementById('{!$Component.page:frm:pblck:pbSectn:pbSitemLastName:contactLastname}').value = '';
 
    alert();
    return false;
    }
   
    </script>
   
   
</apex:page>



Thank You

Tuesday, 10 September 2013

Hide Recycle Bin from Home Page Layout : 2 Minute Recipe



Salesforce doesn't provide specifications to remove Recycle Bin from Home Page.But there are situations which demands that the Recycle Bin shouldn't be shown over the Home Page. In such adverse situations JavaScript is our Best Friend.


First Let me tell you about this Dustbin of Salesforce.

The Recycle Bin link in the sidebar lets you view and restore recently deleted records for 15 days before they are permanently deleted.You can read more from here.

Follow the following steps to Hide the Recycle Bin.

1. Click on Name > Setup > Customize > Home > Home Page Components.
2. Click on New to add a New Custom Component. 


    Give it a unique name of your choice and Select HTML Area and Continue.

    Make sure that you have checked WIDE COMPONENT and SHOW HTML Checkbox.


    Paste the Code provided.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<span id="hideMyParentsp">
</span>
<script>
$(document).ready(function() {  $('#sidebarDiv #hideMyParentsp').parent().parent().hide();      });
</script>

<script type="text/javascript">
window.onload = function(){
var x=document.getElementsByTagName("img");
for(var i=0;i<x.length;i++) {
  if(x[i].title=='Recycle Bin')  {
     var dtag = x[i].parentNode.parentNode.parentNode; dtag.style.visibility='hidden';
      }
 }
var xx=document.getElementsByTagName("span");
for(var ii=0;ii<xx.length;ii++) {
  if(xx[ii].innerHTML=='Recycle Bin')  {
 xx[ii].style.display='none';
  }
 }
 };
 </script>


    Click on Save.

3. Next we need to add this component on Home Page Layout.For this Follow the following Steps
   
    Click on Name > Setup > Customize > Home > Home Page Layout.

    Select "Edit" for your Layout from which you want to remove Recycle Bin.
    Check the Component which you just created in Wide Column Display , Click Next

    Click Save , Additionally you can see the preview.


  You can see the changes in your Home Page. Recycle Bin is No More. You can say that his soul is with us [as it is just hidden] but his body left the mortal world.

  I also lost my recycle bin the same way. write , comment me for some condolence at       gautam.salesforce@gmail.com

  Happy Hiding.

Thursday, 8 August 2013

Batch Apex & CSV Parsing - I am Lovin'it !!


Situation :

I have a CSV File with 3 Fields Lead ID , Yes|No Field and Operator Name.
Without Using Data Loader I need my Data Entry Team to Upload this File  and Leads get updates with these values in the respective fields.



Solution :

Perhaps , Data Loader is the Mirror Cracking Solution. But you cannot get all the happiness at once.

Making the Data Entry team familiar with Data Loader and expecting that they will do correct is like expecting a lion not to eat you all because you are a Vegetarian.

So , Clear Cut My Process was turned up to Batch Apex CSV Parsing . Yes ! You Heard It Correct Batch Apex CSV Parsing .

So , I went to my Manager with this serving on Plate...

I will create a Visualforce Page with a Browse Button.
When a CSV File with Correct Format is Uploaded from there.It will call an controller which will call the Batch Process . The Batch will call a class which will insert records from the values which it gets from another class. Make Sense ?

His words "Sounds Delicious !! "

So , I started upon it .. Here are the ingredients

1.  Page -- BatchUpdateLeads

/* This will be the Visualforce Page with the Browse Button. /*

2. ctrlUpdateallrecFromCSV

/* This will be the Extension which will be called from the Page. /*

3. BatchProcessor

/* Called from the Extension, This is the Actual Batch Process. /*

4. BatchSObjectFeeder

/* This will be an Input for the Batch Apex in its Start Method. /*

5. ctrlAdddataFromCSV

/* This will be the called from the Batch Apex. "InsertValues"  Method will be called. Also , This is the class responsible for Saving the Records in Salesforce. /*
6. clsAdddataFromCSV

/* This is the Class called from ctrlAdddataFromCSV , The main process of this is to parse the excel sheet  . /*



Get the Code from Here ..
Disclaimer : This is a chain of classes as I respect OOP Concepts.


Hope it works well for you all !

Happy Batch Update !! :-)