Wednesday 23 December 2015

Advanced Formulas by Salesforce Trainhead

As we all know formulas are very power tool which let you know calculation result very quick without single line of apex code. It saves a lot of time and avoid apex customization and all. 

Salesforce recently added a great explanation over advance formula in to Trailhead just to let us learn more and more about formula's concept. 
I have gone through with deep dive and I liked the way of explanation as I always see on trailhead no matter if you are newbie/intermediate/Specialist. 

On this trail it explains Advance formula with different return types:
Checkbox, Number, Percetage, Currency,Date/DateTime etc. 

Also covering how to use Text & picklist field values in formula.

Let me cover a these in bit more detail.
1. It explains how checkbox plays important role in to formulas & how we can use IF(), AND(), NOT(), and OR() functions in these formulas. Just to play with it click here
Using Basic Logic in Checkbox Formulas
2. It explains the difference between the number, currency, and percent types & also describe use cases for formulas with the number, currency, and percent types.Just to play with it click here
Using Numbers, Currency, and Percentages in Formulas
3. explanation to build and avoid confusion between usage of Date and DateTime formulas.Just to play with it click here
Using Date and Date/Time Formulas
4. Also explains how to refer picklist field in formulas & some use cases for formulas that reference picklist fields.Just to play with it click here
Using Picklists in Formulas
5. and at last it covers about text type formulas.Just to play with it click here
Using Text Formulas

Tuesday 15 September 2015

New Lightning Experience Content over Traihead

Salesforce always brings new things but this time it brought amazing, fabulous thing for all of us no matter if we are Developers, Admins, Salesforce Rep.

"Salesforce brought-up a new Salesforce." it is nothing but new Lighting experience along with supporting classic one.

And also provided a great tool for getting started with it in easiest way. As I am developer so would like to bring you deep in new lightning dive.

Developer Trail - Lightning Experience | Salesforce Trailhead

So come with me visit few of my favorite content putting over there.

Lightning Experience Basics

To respond millions of feedback Salesforce bring some thing new which can
1. Fill gap between Dev, Admin & Sales Rep.
2. Save precious time of customer to do any activity in minimum clicks.
3. Help develop, access Apps compatible for different devices whether it is Desktop, Mobile or Tablae.

So Salesforce introduced new Lighting Experience. It faster, beautiful & more interactive. It is very easy to switch to or back to previous one based on user's preference.

Best feature I liked most is that Salesforce has given all control to end user for  getting new look & feel (experience) of doing things quickly just like light flash that's why it was called Lightning Experience.

in this series I have another content I would love most is

Using Visualforce in Lightning Experience

After getting a basic idea now next thing is to customization do lets go to development corner. Although we are moving ahead to new lightning experience but salesforce continue to support existing Visualforce development for Salesforce classic (existing Salesforce) as well as allowng visualforce development in new lightning experience.
Here are few steps like
build VF page-> Create Tab for it -> custom App and make it available in App Launcher.

A smplified way to test your page in Lightning Experience is just type the following into your JavaScript console as below:


$A.get("e.force:navigateToURL").setParams({"url": "/apex/pageName"}).fire();


now question raised that will Existing VF page will also work on new Lightning experience  then answer would yes but not fully as we need to make some required changes to do this.

so for more information you can quickly visit :https://developer.salesforce.com/trailhead/trail/lex_dev


Friday 4 September 2015

JSON Data Binding in Apex

While playing with JSON I came up with intersting usecase of binding JSON data in Class properties.

Here is JSON Data:
[ 
 {
  "ProductionHouse":"ABCD", 
  "Director":"Mr XYZ", 
  "Casting": [
   { "Title": "Play1", 
   "Artists": ["Artist1", "Artist2", "Artist3", "Artist4", "Artist0"]   
   },    
   {
   "Title": "Play2",
   "Artists": ["Artist1", "Artist2", "Artist0"] 
   }
  ]
 }
]
in order to coupling this data with some real time properties I have written below logic :
 Public Class Play_Controller{

    // JSON data binding with Class properties 
    public static void Databinding()
    {
        String inputJSON= '[    {   "ProductionHouse":"ABCD","Director":"Mr XYZ","Casting": [{ "Title": "Play1","Artists": ["Artist1", "Artist2", "Artist3", "Artist4", "Artist0"]             },  {"Title": "Play2","Artists": ["Artist1", "Artist2", "Artist0"] }]}]';
        List DataMainwrapperList = new List();
        DataMainwrapperList = (List< DataMainwrapper >)JSON.deserialize(inputJSON, List.class);

        for(DataMainwrapper Obj : DataMainwrapperList)
        {
            system.debug('---Prod House Name--'+Obj.ProductionHouse);
            system.debug('---Director--'+Obj.Director);
            for(CastingSubWrapper subobj : obj.Casting)
            {
                system.debug('---Play Title--'+subobj.Title);
                system.debug('---Play Artists--'+subobj.Artists);
            }
        }
    }
    
    // Wrapper holding properties of JSON with data upper leve
    public class DataMainwrapper{
        String ProductionHouse;
        String Director;
        List Casting;
    }

    // Wrapper holding properties of JSON with data sub level
    Public class CastingSubWrapper{
        String Title;
        List Artists;
    }    
}
//--Please Ignore below code line--
Further we can bind this data in respective objects in Apex. So I hope now it will helpful to understand how JSON data may enter in salesforce.

Thursday 27 August 2015

Meet the New Salesforce

Hi, All Customer, Developers, Admins.

It doesn't matter you do code or not but the thing today I am talking about, is for you. It is new Salesforce in form of experiencing new design.


After Trailhead announcement Salesforce made a biggest announcement in their release. It is bringing a new face of Salesforce to us. Now Salesforce letting customers design their screen.






There are key notes behind this new change:

Customer Adoption:
After hearing many useful feedbacks Salesforce implemented this new design in such a way that it is easy, fast & successful for all customers for easy to adopt.

Easy Switching :
Now Salesforce unveiled this in new face of CRM package which is completely redesigned version. It is new kind of interface, Salesforce built which will let us feel something new over the existing layer but will keep supporting existing UI(classic version) so that we can easily switch in between both versions.

Design System:
Through lightning salesforce made process more faster using drag & drop concept to configure new design which clearly reflect clarity in idea,efficiency, consistency & beauty in it.

Scope:
It is just a starting with building CRM package over lightning and in future many more things are lined-up with new version.

Browser Support:
New version would be supportive on all browsers like IE 11, Safari version 8, most recent stable version of firefox & chrome. while using lower version of IE it will automatically switch to classic version.

When it will be available?
It would be in our orgs in next Winter Release but it might be available on some pre release orgs for early access. There is a way to complete some lightning trails in order to be on priority for getting early access releases.

For more detail watch the complete session here : Meet the New Salesforce Live from San francisco

Wednesday 19 August 2015

Salesforce integration with Salesforce

Accessing Apis of external system is call integration in simple words. Here I will talk about how salesforce org gets integrated with another salesforce org.
Going forward I would call these two Salesforce orgs as Source org & Target org.

Requirement: Requirement is to fetch user information from target org in to source org.

Step1. It is the master key point that always you have to build an App in Target Org so now you need to create a connected App.
Once you have created Connected App then you get two important keys :
1. Client ID
2. Client Secret

These are common keys which you get while creating connected Apps.

Step2. Now you need to write a VF page and Apex class.
VF page


Apex Class
Note: Here you have to use client id, client secret & redirection URI in below class:

public class SF2SFIntegerationcontroller {

    string code;
public Pagereference SF2SFIntegerationClassMethod()
{   
    String clientId ='xxxxxx';// 
    String clientSecret = 'YYYYY';    
    String redirecurl = EncodingUtil.urlEncode('https://csopke1.ap1.visual.force.com/apex/SF2SFIntegeration','UTF-8.');
    
    if (ApexPages.currentPage().getParameters().containsKey('code') && ApexPages.currentPage().getParameters().containsKey('code') != null) 
    {
        code = ApexPages.currentPage().getParameters().get('code');
        String oauthURlText = 'https://test.salesforce.com/services/oauth2/token?grant_type=authorization_code&client_id='+clientId+'&client_secret='+clientSecret+'&redirect_uri='+redirecurl+'&code='+code;
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(oauthURlText);
        req.setMethod('POST');
        req.setTimeout(60*1000);
        HttpResponse res = h.send(req);
        String resString = res.getBody();
        OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(res.getbody(), OAuth2.class);
                
        //USAGE
        HttpRequest req1 = new HttpRequest();
        req1.setHeader('Authorization', 'Bearer '+objAuthenticationInfo.access_token);
        req1.setEndpoint(objAuthenticationInfo.instance_url+'/services/data/v29.0/query/?q=SELECT+id,+name+FROM+user+limit+1');
        req1.setMethod('GET');
        req1.setTimeout(60*1000);
        HttpResponse res1 = h.send(req1);
        String resStringfromExternalOrg = res1.getBody();
        system.debug('------'+resStringfromExternalOrg);
        return null;
    }
    else
    {   PageReference pgRef = new PageReference('https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id='+clientId+'&redirect_uri='+redirecurl);
        return pgRef;
    }
    
  }
    /*To get aouthentication detail Wrapper*/
    public class OAuth2{
    
     public String id{get;set;}
     public String issued_at{get;set;}
     public String instance_url{get;set;}
     public String signature{get;set;}
     public String access_token{get;set;}    
    }

}
 

Step3: Now you just need to execute VF page. You might need to setup remote site setting for URIs, you are hitting while executing Page. If any mediator screen asks to allow permission just allow it (to avoid it you need to use target org's credential in your logic) and see the magic in your debug log.

as these two orgs integrated so now You will get user information from target org in to source org.

Salesforce Meetup for Students March 2015

So... It was again a great opportunity for us to organize Salesforce meetup specially for students. many old faces continued and many new started with Salesforce platform.
I would like to express my great thanks to April Nassi and Ankit Arora to support me in my this new sort of initiative.
Now coming to Meeting Notes:

In Last Meetup I discussed about Basic Salesforce as a cloud computing platform so in continuation
Deepak Kumar Shyoran brought-up many important key points we should start with in Salesforce. He related 
Salesforce features with real time events. He explained every point with in such a nice way that Students
could not feel the gap of their current knowledge levels. 

It was not all about theoretical session but we moved further keeping people tuned-up
by asking questions with a new trivia series and distributed very very cool stuff. 

Moving ahead to next level I brought-up Salesforce1 in the discussion box. I tried my best to explain how 
Salesforce came in picture along with Salesforce. What was the need and how it is getting accomplished. 
I covered-up Salesforce1 basics.

but as we know untill unless we see some thing going live in front of us we could not capture it at all so 

Ashwani Soni demonstrated how we can switch to Salesforce 1 by performing very simple steps in 
Salesforce.

So would like to express great thanks to SKIT and all students who joined. 

with regards...
sp

Thursday 6 August 2015

Lightning Component

After Lighting connect one of previous blog now I would like to share some thoughts on lightning component. So what is lightning component?
"The Lightning Component framework is a UI framework for developing dynamic web apps for mobile and desktop devices".

Salesforce has provided us Lightning App Builder to build lighting different Apps using components. The Lightning Component framework is built on the open-source Aura framework available at http://github.com/forcedotcom/aura.

So let me come to the practical example:
There are simple steps to build any lighting components:
Step1: You Name> Developer Console > File > New > Lightning Component. Here Provide Name of Component and click on Submit button.

Step2: For developing lightning component we need to understand below parts mainly as lightning bundle.

a) component
b) controller
c) Helper
d) Style

A component contains the UI part aura tags are being used along with other html tags and it is tightly coupled with Apex controller but here the interesting thing to understand is properties of component are not directly bounded with apex controller while there are two extra layers controller and helper which pays as middle layer. while Style plays role of providing CSS features.

Here I have built lighting application

Component :
 <aura:component access="global" controller="ShowRecordClass" implements="flexipage:availableForAllPageTypes">
 <aura:attribute name="myAccounts" type="Sobject[]">
    <aura:handler action="{!c.getAccRecords}" default="Account" name="init" value="{!this}">
    <aura:attribute name="ObjectApiName" type="String">
    <aura:attribute name="ObjectLabel" type="String">
    <aura:attribute default="5" name="maximum_NoOfRecordstofetch" required="true" type="integer">
    <aura:handler action="{!c.getobjectLabel}" name="init" value="{!this}">
    Here are {!v.maximum_NoOfRecordstofetch}(or less) most recent created Records for Object : {!v.ObjectLabel}
    </aura:handler></aura:attribute></aura:attribute></aura:attribute></aura:handler></aura:attribute></aura:component><br />
<div class="RecordTable">
<div>
<aura:iteration items="{!v.myAccounts}" var="obj">
                        </aura:iteration><br />
<table class="imagetable">
                   <tbody>
<tr>
                       <th class="thcls">{!v.ObjectLabel} Id
                       </th>
                       <th class="thcls">{!v.ObjectLabel} Name
                       </th>
                   </tr>
<tr>
                         <td class="tdcls"><ui:outputtext value="{!obj.Id}"></ui:outputtext></td>
                            <td class="tdcls"><ui:outputtext value="{!obj.Name}"></ui:outputtext></td>                                                      
                        </tr>
</tbody></table>
</div>
</div>

Controller:
({
 getAccRecords : function(component, event, helper) {
  helper.fetchrecords(component);
 },
    getobjectLabel : function(component, event, helper) {
  helper.fetchobjectLabel(component);
 }
})
Helper
({
    fetchobjectLabel : function(component) {
  var action = component.get("c.returnObjectLabel");
         action.setParams({
         sobjeApi : component.get("v.ObjectApiName")            
      });
            action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === 'SUCCESS') {
            component.set("v.ObjectLabel", response.getReturnValue());                
            }
            });
            $A.enqueueAction(action);
 },
 fetchrecords : function(component) {
  var action = component.get("c.fetchRecord");
         action.setParams({
         sobjeApi : component.get("v.ObjectApiName"),
            numberofRecords : component.get("v.maximum_NoOfRecordstofetch")
      });
            action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === 'SUCCESS') {
                console.log('=**=');
            component.set("v.myAccounts", response.getReturnValue());      
            }
            });
            $A.enqueueAction(action);
 }
    
})
Apex Controller
Public Class ShowRecordClass{

@AuraEnabled
Public Static List fetchRecord(String sobjeApi, Integer numberofRecords)
{
    List LstOfAcc = new List();
    LstOfAcc  = Database.query('select id, Name from '+sobjeApi+' Order by CreatedDate DESC limit '+numberofRecords);
    return LstOfAcc  ;
}
@AuraEnabled
Public Static String returnObjectLabel(String sobjeApi)
{
   String finalString  = Schema.getGlobalDescribe().get(sobjeApi).getDescribe().getLabel();
   if(finalString  != null && finalString  !='')
       return finalString  ;
   else
        return sobjeApi;
}
}
Style:
.THIS table.imagetable{
    font-family: verdana,arial,sans-serif;
 font-size:11px;
 color:#333333;
 border-width: 1px;
 border-color: #999999;
 border-collapse: collapse;
}
.THIS th.thcls {
    background:#b5cfd2 ;
 border-width: 1px;
 padding: 8px;
 border-style: solid;
 border-color: #999999;
}
.THIS td.tdcls {
    background:#dcddc0 ;
 border-width: 1px;
 padding: 8px;
 border-style: solid;
 border-color: #999999;
}
Now we can use this component in lightning Apps or lightning App builder.
<aura:application>
    <c:showrecentcreatedrecords maximum_noofrecordstofetch="6" objectapiname="Account">
</c:showrecentcreatedrecords></aura:application>
Here I am using it in lightning App. Here is the Lightning App preview. To preview go to App and click on preview in right hand side bar. There is one benefit that we can show more than 1000 items of single list on UI which just over come the limit of visualforce page.

Tuesday 4 August 2015

Salesforce to Salesforce

When it comes to deal with migration/sharing of data within salesforce orgs then no need to worry about. Salesforce provides a native feature Salesforce to Salesforce in short "S2S". It can also be used to create this data sharing relationship. Lets take a example of two orgs org1 and org2 and we need to share Account and Opportunity Data within orgs then this can be done easily in below steps:

Step1. Enable Feature Salesforce to Salesforce in org1 and org2 both.
Note: Once it is enabled it will be not be disabled. Setup-> App Setup-> Salesforce to Salesforce
                                                    

Step2: Now create an Account and contact record with email id of contact person of org2

Step3: Now Setup a connection in Salesforce org1 and send invitation to org2. Note: if connection tab is not visible then please make it visible to current app.
Step4: An Email will be sent to email address provided on contact ask to insert in previous steps. Once we click on link of email body it will redirect us to login screen.

Step5: Enter credential of org2 it will be redirected on invitation acceptance screen.

Step6: Now Publish Account and Opportunity objects along with fields in org1.



Step7: Now Subscribe objects in org2 and keep field mapping with setting up auto accept.
Step8: Now we all set.

Once we create Account ( with Opportunity record) and then in list view of Account click on "Forward to Connection". Select Connection name and proceed further allowing to forward opportunity data. You will see in org2 same set of record will be created with same values filled in org1 (when fields are properly mapped).

Limitations: Lookup IDs are not available for publishing. You can enable S2S for those fields by creating a formula field and then publishing the formula field.



Tuesday 23 June 2015

One thing you must know about Junction Objects in Salesforce

Hi Devs, Here I brought-up some thing new I hope in very common topic Junction Object In Salesforce. 

So what I am talking about here is when we setup junction object and go to any of the master record and see related of detail records then there will not be edit link in front of record in the list until unless we have one custom field over that detail object. 

Let's take a example. I have two custom Objects Master1, Master2 now I am going to create one junction object under Master1 and Master2.
                       











When I visit Master1 record then I observe that edit link is not there
                       

but if I view that junction record separately then I have Edit button on junction record page.
                                     

So Here is the reason as I create a editable custom field on junction object

                                  

"Edit" liks gets appeared in the related list but it is not necessary to keep that field on layout keep it behind the screen.
                                     

Sunday 21 June 2015

Lightning Connect


Its a time to connect salesforce to other system for data perspective then easiest option provided by Salesforce is lighting connect. 
It connects and access data from external sources with point-and-click simplicity. It Incorporate data from legacy systems (SAP, Oracle, Microsoft, etc.) in real time in Salesforce application objects. 

How to set-up : 
There are two type of entities which need to setup in order to work on lightning connect. 
1. External Data Source 
2. External Object 

Goto Setup>Build>External Data Source and Create a new External Data Source which will keep reference of an external hosted data source. 

1. Select option "Lightning Connect: OData 2.0" then Salesforce connect to external data server. The external data must be exposed by a service that uses Open Data Protocol (OData) Version 2.0. Such a service is called 
an OData producer.               


2. Select identity Type "Anonymous" then no authentication is required but if you select other option than it will ask authentication from different ways like Oauth2.0, password authentication. 
In my example I have put one OData supported data and then select Anonymous identity types and put URL with 
http://services.odata.org/V2/(S(z03hdcomixoupwtkwk3as00w))/OData/OData.svc/ 
After creating this external Data Source, we need to create External Object. For this I have clicked on Validate and Sync button and I was redirected to next screen where I found table with option to select object data I wanted to inherit. Once I select object and click on Sync option, external Object got created.

Here I have selected two objects "Categories" and "Products" so resulting two external objects have been created.


These External objects can not be modified within Salesforce but these synced with external system. 


we can read the data either via visiting record file or applying SOQL. This data does not count against Salesforce storage limit. 
Here is data :

Friday 20 March 2015

Trailhead over force.com Basics


Whenever we move ahead to learn a new technology or platform we firstly look for basic level tutorial. How it would be great if it come along with examples and challenges to check our knowledge. 

So Trailhead is formed in such a way that gives us a structured way of learning Salesforce with different - different modules. 

I like module "Force.com Basics" most. Trailhead has categorized it in three simple steps


On very first time we badly need an introduction of platform or feature forgetting started with it. In Trailhead it is defined in below way : 
a) Signup process
b) first App Creation explained in very simple steps it shows power of "Point & click process" 
c) then explained some general areas and terminologies.
The Force.com signin page.
Moving ahead Trailhead presents navigation steps of "setup sidebar" to us it is just like a library of features salesforce provides so far and enabled in our org. Each and every option is very well defined and snapshots were such informative for us. 
The username menu, with Setup highlighted
The Developer Edition setup page.
Last but not least it would be cherry on the cake for all code lovers. Debugging is most important in order to verify that our logic works correctly.

It is a collection of tools which has its own capabilities like 
a) Executing logic 
b) logging
c) Running Test cases
d) Interaction with database using query editor 
... and many more.
Force.com Developer Console layout
So I really love this module which is backbone of Salesforce technology and must to learn. 

In every topic coverage area we meet with all challenges available for us and make us more focused and attached with the module topic we just covered. 

Thanks Trainhead | Go Trainhead | Learn something new






Sunday 8 February 2015

Salesforce Components Daily Automatic Backup Process

Dev Folks, 

Being a developer components management are most important part for us in any application. So we need backup always. 

But again taking-up a backup is very tedious/time taking challenge. So here I am presenting a process to setup Salesforce Components Daily Automatic Backup

For this first of all, you need ANT setup in our machine. If you want to know how to setup ANT, please visit one of my previous blog How to Setup ANT.

Moving ahead now we need to setup a folder like below


In above folder we should have:
1.) Build.xml 
2.) Build.properties 
3.) run.bat 

for All sample files you can click here .

Now it is time to our schedule backup script in windows scheduler. For this Please follow below steps 

Step1. Open Windows Scheduler->Create Basic Task-> Provide Name of the Task


Step2 : In Trigger select "Daily" 
Step3 : In Action fill what time you want to schedule it 
Step4 : In Action "Start Program" 
Step5 : In "Start Program" provide path of run.bat


Step6 : click on finish. 

Now all Set and so enjoy your work without worrying about your backup.