Saturday 24 December 2016

Switching to Lightning in Easy Way...


Hey folks,

Since last so many years I am living with one of the best UI framework that is Visualforce. It is such an amazing part of salesforce which helps a lot for interacting, an end user with application.

Time by time, as we are switching to mobile devices which are so handy as well as supportive to our life style for providing all the information on the go. A series of technologies are being used for displaying information quick & in responsive manner according to device your are with, regardless of size.

In order to show information in responsive way, we need many technologies. So along with developing logic we need to take care of responsiveness too.

"How easy it would be if it responsiveness gets handled automatically without require an extra efforts. Is there any solution available in salesforce ?"

Yes Lightning is here !!

Lightning component take care of it and let you focus only on developing business logic.

So if you are still on visualforce then here are some tips to understand how to move to lightning.

  1. Lightning component is based on Aura (an open source UI framework) that supports HTML tags also and can be easily bind with apex controller.
  2. You may get started building lightning component through developer console it self.
  3. Lightning component may overcome many problems that you face in visualforce. For example we can not show more than 1000 items in visualforce page directly binding collection to VF page but lightning component allows it.
  4. Using lightning component, you may keep your application structured that is very easy to maintain.
  5. As visualforce are page-centric, meaning we have to do most of the things on server side but lightning component are based on client-side-centric so before switching to lightning, this should be considered as per your requirement.

Here is one of my Blog post regarding how to develop lightning component.
Go #Lightning!!

Friday 12 August 2016

How to Combine Documents through Docusign APIs

This time I got a chance to play with inner world of Docusign. Always I prefer REST API but this time SOAP saved my life.

I had a challenge to combine all signed document in single enevelope ( condition is you can not get it through Docusign configs settings because that is common for) so I have used soap api this time over rest ( was giving me Time out error).

Required Data:  Docusign Credential , Integrator Key & EnevelopId.

Firstly created a class 'DocusignSOAPfromWSDL_Cls' trough wsdl file then written our logic to get all document in combined format. Below is my code snippet:


// To Set endpoit URL
dsApiSend.endpoint_x = 'https://demo.docusign.net/api/3.0/dsapi.asmx';

// To Set Authentication
String auth = '<DocuSignCredentials>
                                <Username>'+ DocusignUserName+'</Username>
                                <Password>' + DocusignPassword + '</Password>
                                <IntegratorKey>' + Docusign_IntegratorKey + '</IntegratorKey>                                                 </DocuSignCredentials>';

// To Set Headers        
dsApiSend.inputHttpHeaders_x = new Map<String, String>();
dsApiSend.inputHttpHeaders_x.put('X-DocuSign-Authentication',auth);      

//Interating all incoming docusign status records
 DocusignSOAPfromWSDL_Cls.EnvelopePDF combinedPDF = dsApiSend.RequestPDFNoWaterMark(docusignEnvelopeID);
       Attachment combinedDocument =  new attachment(
                                           Body=EncodingUtil.base64Decode(combinedPDF.PDFBytes),
                                           Name= AttachmentName+'.pdf',
                                           parentId= ParentRecordId
                                    );
      insert combinedDocument ;

This is how you may combine all signed document through Docusign.


Thursday 4 August 2016

Finding nearest locations on google map within Salesforce

Locating anything is just part of our daily habit. Salesforce made is very easy by adding Geolocation to Address field types. So I have did one practice to locate nearest restaurants on google map.

Lets Say I have one Company Record and would l like to plot all restaurants that are located in x unit of distance to company on google map.

To achieve this I am going to use two features of salesforce one is Distance formula

DISTANCE(AddressField, GEOLOCATION(latitude,longitude), 'mi')

and another one is apex:map & apex:mapmarker tag

Visualforce page:

<apex:page controller="findrestaurantsController">  
      <apex:pageBlock >
         <apex:pageBlockSection title="Nearest Restaurants" >      
            <apex:map width="600px" height="500px" center="{!mylocation}" zoomLevel="5">
                <apex:repeat value="{!NearestRestaurantsList}" var="nearestPos" >
                    <apex:mapMarker position="{!nearestPos.location}" title="{!nearestPos.RestaurantName}"/>
                </apex:repeat>
            </apex:map>          
         </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Controller:
public class FindrestaurantsController {

  // Public Properties
  Public map < String, decimal > mylocation {
    get;
    private set;
  }
  Public List < NearestRestaurants > NearestRestaurantsList {
    get;
    set;
  }

  Public FindrestaurantsController() {
    Company__c Company = new Company__c();
String CompanyId = ApexPages.currentPage().getParameters().get('id');
    Company = [Select Id, Name, Location__latitude__s, Location__longitude__s From Company__c Where Id =: CompanyId];

    mylocation = new Map < String, Double > {
      'latitude' => Company.Location__latitude__s,
      'longitude' => Company.Location__longitude__s
    };

    String queryString =
      'SELECT Id, Name, Radius__c, Location__c, Location__longitude__s,' +
      'Location__latitude__s ' +
      'FROM Restaurant__c ' +
      'WHERE Id != \'' + Company.id + '\' AND DISTANCE(Location__c, GEOLOCATION(' + Company.Location__latitude__s +
      ',' + Company.Location__longitude__s + '), \'mi\') < ' +
      Company.Distance__c + ' ' +
      'ORDER BY DISTANCE(Location__c, GEOLOCATION(' + Company.Location__latitude__s + ',' + Company.Location__longitude__s +
      '), \'mi\') ';

// Getting nearest Restaurant records
    List < Restaurant > otherRestaurants = new List < Restaurant > ();
    otherRestaurants = Database.query(queryString);

    NearestRestaurantsList = new List < NearestRestaurants > ();
// Building wrapper List
    for (Restaurant otherRestaurant: otherRestaurants) {
NearestRestaurants wrapItem = new NearestRestaurants(
                             new Map < String, Double > {
                                    'latitude' => otherRestaurant.Location__latitude__s,
                                       'longitude' => otherRestaurant.Location__longitude__s              },
                                       otherRestaurant.Name);

NearestRestaurantsList.add(wrapItem);
    }

  }

  // Wrapper Class to store nearest restaurants detail
  Public Class NearestRestaurants {
    Public map < String, decimal > location {
      get;
      private set;
    }
    Public String RestaurantName {
      get;
      private set;
    }
    public NearestRestaurants(Map < String, Double > nearestlocation, String myResName) {
      location = nearestlocation;
      RestaurantName = myResName;
    }
  }
}

Thanks for reading this post. 

Tuesday 5 July 2016

Salesforce disabling TLS 1.0 Solution


As we all know Salesforce disabled TLS 1.0 so any inbound connections to or outbound connections from your Salesforce org will need to use the TLS 1.1 or TLS 1.2 encryption protocol

So if have been going through below issue (like me)

Why do I see the error: TLS 1.0 has been disabled in this organization. Please use TLS 1.1 or higher when connecting to Salesforce using https

& if you are in Summer'16 then Here is the solution for 

1. Eclipse: 
In your eclipse folder, there should be eclipse.ini file Please open file and add below 
keyword
-Dhttps.protocols=TLSv1.1,TLSv1.2


2. Migration Tool Like ANT: 

Add below variable in environment variables. 
Variable Name : ANT_OPTS  
Variable value  : -Dhttps.protocols=TLSv1.1,TLSv1.2

Sunday 19 June 2016

How to handle a 301 redirect response to my HTTP callout

While trying out https callounts we typically see response with Status=Moved Permanently, StatusCode=301. Below is the code sample which gives us error:
Http h = new Http();
HttpRequest req = new HttpRequest();
     
req.setHeader('Authorization', 'bearer ' + 'xxxxxxxxxx');
req.setEndpoint('https://www..com/v1.2/accounts');        
req.setMethod('GET');
req.setHeader('Content-Type', 'application/json; charset=UTF-8');
req.setTimeout(60*1000);
HttpResponse res = h.send(req);
String resString = res.getBody();
This errors generally occurs when target point we hit for, has permanently moved to a new location so in this case response should include this location. to fix this error we just need to get location out of first response and hit it again.So Finally code should be like below:

Http h = new Http();
HttpRequest req = new HttpRequest();
       
req.setHeader('Authorization', 'bearer ' + 'xxxxxxxxxx');
req.setEndpoint('https://www..com/v1.2/accounts');        
req.setMethod('GET');
req.setHeader('Content-Type', 'application/json; charset=UTF-8');
req.setTimeout(60*1000);
HttpResponse res = h.send(req);
String resString = res.getBody();
String loc = res.getHeader('Location'); // get location of the redirect
req = new HttpRequest();
req.setEndpoint(loc);
req.setMethod('GET');
req.setHeader('Authorization', 'bearer ' + 'xxxxxxxxxx');
        res = h.send(req);

Now it gives Status code 200 with Status "OK"

Tuesday 15 March 2016

Delete Components before and after Component Updates in a deployment in Salesforce

Guys, As we all know that Ant is such a great migration tool. I have described how we can set-up ANT on our local machine and migrate desired component to Salesforce org.

Today I am going to describe how we can delete component from salesforce org using ANT. Salesforce has provided a way of achieving it through some well defined desctructiveChanges.xml .

Later on, it would took two at least migration attempts for clearing-up dependencies between components and deleting those respectively.
For example if one custom field is being used by an apex class then we can not delete that field until we remove that field's active presence from apex class. For this purpose, Salesforce unveiled two new type of xmls

1. destructiveChangesPre.xml
2. destructiveChangesPost.xml

Lets understand with an example. Let say there are two fields amount__c,department__c on Account Object and there is one class ShowingResult that use one field amount__c.
Public class ShowingResult {

   Public void ShowingResult()
   {
       Account acc = new Account{Name = 'testAcc', amount__c = 1232};
       insert acc;    
   }

}

In order to delete these two fields we need to make some required changes in apex class first. then system would allow us to delete amount__c field. Generally it would take two steps but the way is described below would do our job in one attempt.

Here is your modified Apex Class:
Public class ShowingResult {

   Public void ShowingResult()
   {
       Account acc = new Account{Name = 'testAcc'}; // with modification
       insert acc;    
   }

}

Now we just need to create three xml files(as below) and run these.System would run desctructiveChangesPre.xml then package.xml for updating component where we have removed dependencies. finally it would run desctructiveChangesPost.xml.
Your desctructiveChangesPre.xml

    
        Account.department__c
        CustomField
    
    36.0

Your Package.xml:

    
        ShowingResult
        ApexClass
    
    36.0

Your desctructiveChangesPost.xml:

    
        Account.amount__c
        CustomField
    
    36.0

Keep these xml in src folder and run migration.

Saturday 27 February 2016

SandboxPostCopy : featured Post Refresh Activity

Hi Folks,

Today I am going to discuss about a very beautiful features Salesforce just released. This features to make your sandbox environment business ready, automate data manipulation or business logic tasks.

While creating/refreshing any sandbox from you may need to run any logic just after completion of refresh so now it is possible using this feature called "SandboxPostCopy" interface.

Here I am taking an example where I need to create some couple of records of an opportunity object just after completing with refresh activity.

I should have a class in production as below


global class createOpportunity implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {
        // write your logic to create opportunity
     }
  }

then while refreshing/creating sandbox you need to select this class to be executed as below:



Thanks for reading.!!




Friday 19 February 2016

Trailhead Trail: Navigate the Salesforce Advantage

Salesforce never sleeps ..

As we all know Salesforce brings new and exciting things for us day to day & specially through Trailhead.

This time Salesforce launched a new trail which let us know about many key differentiators , core values & vibrant ecosystem in very simple way as it alwasy does.

Here is the path :  Navigate the Salesforce Advantage

It designed so beautiful that you will learn a lot along with fun story. It is 80 mins ( ideally ) trail. where you will know :

Salesforce Success Model  | Salesforce Cloud Benefits | Salesforce Technology Basics | Salesforce Ecosystem

It is useful for all who are already familiar Salesforce but specially who are newbie.

Let me bring my views over every Module of this trail:
Salesforce Success Model

It introduces Salesforce to you in a different way and very beneficial if you would like to grow as company as fast as you can.


It explains beautifully that salesforce is a complete CRM and how it would become more beneficial as it is available on cloud. There are ample benefits of having cloud platform rather than traditional systems. How salesforce cloud gives us more advantage.




When it talks about basics it brings many thing which essential to know like how Salesforce care about trust of customers, How system provides multitenancy to use system more efficiently/productively. 
How we can understand technical concept though real life examples which is such a great way to learning. e.g. metadata. 
also explains how user can decide if app should be developed by either point & click or coding.

it gives a message that we all are together, we can make progress helping to each other thats why community was built. Appexchange was introduced, local user group events are being organized.

So event I have been associated with salesforce since last many years but still many new things while doing this trail.

What I feel: 
  • This trail really helpful to dev, admin to understand salesforce from in a new way and related with what experience they are getting over the years working on salesforce platform.
  • I would love one of four core differentiators that is customer success. It really matter like if your custom is happy and getting success it feels you happy and more confident while delivering more and more. 
  • So I have done this trail !! what you are waiting for ??  Thanks Salesforce Trailhead for giving such innovative ways of learning. 
Thanks everyone for reading the post.