Month: April 2019

Google translate service in Salesforce

Google translate service in Salesforce

For translating Languages, we are trusting Google for years and it is also a very dependable and accurate so what if we can use that service in salesforce itself.
wouldn’t it be so amazing?
yeahhh, you are right. we can use google translate service in salesforce and it doesn’t need very complex coding and configuration.

so let’s start now-

first we need to create a project in our google account as per the image below

Then go to your console –

In API Library, search for Cloud Translation API and activate it
it will ask for billing information and you need to add your payment method or card information then you can activate this service.
Probably they will give you first free 300$ in your account for testing these services and they will not debit any money without your permission.

Then you need to create credentials in that API and that will be called API key which we will use for authentication from the third party.

Now everything is set up on Google Translate API side now we need to code on salesforce side.

For calling out google api, we have to add remote side setting with this URl:

If you will check the URL then it has source and target language both, because when we define our source language then Google doesn’t need to detect the language so they will charge less for the translation.

you can use below code in developer console and get the result in debug-

String a = 'I'm getting bombarded with scam calls threatening to arrest me.';
String text = a.replace(' ', '%20');
//Change your key here
String Key = 'AIzaSyB***************YKi-4hpZ1Dgvo';

HttpRequest req = new HttpRequest();
Http http = new Http();

string url = ''+key+'&source=en&target=es&q=' + text;

System.debug('URL ' + url);
String jsonResults = '';
HTTPResponse resp = http.send(req);
jsonResults = resp.getBody();

we are using version 2 of this API but they also introduced new version 3 which has additional features like a custom dictionary and Batch requests.
if you need those functionalities then you can go with version 3.


you can check pricing in this link

  • Price is per character sent to the API for processing, including whitespace characters.
  • Prices are ‘pro rata’ (proportional and incremental). For example, if you send 75,000 characters for processing within a month, you are charged $1.50.
Convert VisualForce page into Lightning with no efforts

Convert VisualForce page into Lightning with no efforts

For the Lightning transition, we don’t need to convert all our visualforce pages to lightning component because visualforce pages works in lightning experience.
we prefer to convert only those pages in which we need the speed of lightning so that the productivity of the user could be increased.

Pages which are not very complex in structure and delivers basic functionality, we don’t want to put so many efforts on them
And Lightning transition is a very big activity so It’s a good idea that we don’t spend too much time on simple pages and just use them as it is.
But if we are in lightning and everything looks beautiful and these small pages could make our beautiful transition ugly.

So the scenario is –

  • we need to migrate to Lightning but we have less time.
  • Need common look and feel for all pages and components.
  • Don’ want to make efforts to rebuild these pages.

If you can relate to these above points then you are at the right place ;p

This trick can help to save your time, money and efforts

This piece of code determines weather user is in classic or Lightning.

public boolean getIsClassic()
return (userInfo.getUiThemeDisplayed() == ‘Theme3’);

In Vf page we use SLDS style only when user is in Lightning experience.

<apex:page standardController=”Case” extensions=”CaseController” standardStylesheets=”{!IsClassic}” LightningStylesheets=”{! !IsClassic}”><apex:outputPanel rendered=”{! !IsClassic}”>
<apex:slds />

If some of the components like the pageblock table is not rendering smoothly then you can use some custom styling and place it inside the same output panel.

<apex:page standardController="Case" extensions="CaseController" standardStylesheets="{!IsClassic}" LightningStylesheets="{! !IsClassic}">

<apex:outputPanel rendered="{! !IsClassic}">
	<apex:slds />
	body .bPageBlock .detailList .dataCol {
		margin-bottom: 0rem !important;
		margin-top: 0rem !important;
		padding-top: 0rem !important;
		padding-bottom: 0rem !important;
		display: table-cell !important;
	body .detailList .dataCol select{
		min-width: 15rem !important;
		width: 15rem !important ;
	body .dataCol textarea {
		min-width: 15rem !important;
		width: 15rem !important ;
		height: 45px;
	body .pbSubsection{
		padding-top: 0rem !important;
		padding-bottom: 0rem !important;
	body .detailList tbody tr{
	width: 250px;
	body .bPageBlock .pbSubheader{
		margin-bottom: 8px !important;
		line-height: normal !important;
	body .pbHeader .pbButton{
		text-align: center;
	body .pbButton .btn, body .pbButtonb .btn {
		background-color: #9e801a;
		color: white;