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.