Friday, 18 August 2017

An error occured while serving your request Email already registered in Salesforce Einstein

Whenever you are sign up for Einstein Platform Account and failed to download key

You can just reply to the same email and delete your account and again create a new one.

As I found there is no specific official document provided by the product team.


Tuesday, 16 June 2015

Google Map Integration in Salesforce

VF Page Name : GMAPINT


<apex:page standardController="Account">

<script src="http://maps.google.com/maps?file=api">
</script>

<script type="text/javascript">

var map = null;
var geocoder = null;

var address = "{!Account.BillingStreet}, {!Account.BillingPostalCode} {!Account.BillingCity}, {!Account.BillingState}, {!Account.BillingCountry}";

function initialize() {
if(GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("MyMap"));
map.addControl(new GMapTypeControl());
map.addControl(new GLargeMapControl3D());

geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point) {
if (!point) {
document.getElementById("MyMap").innerHTML = address + " not found";
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.bindInfoWindowHtml("Account Name : <b><i> {!Account.Name} </i></b>
Address : "+address);
}
}
);
}
}
</script>
<div id="MyMap" style="width:100%;height:300px"></div>
<script>
initialize() ;
</script>

</apex:page>


Now type in URL ".../apex/GMAPINT?id=YOUR_ACCOUNT_ID".

e.g. ".../apex/GMAPINT?id=001k000001QUrSR".

Salesforce Visualforce Page Code Generator

Visualforce page code with a button click, reduces time to write VF page again and again.

Install the package : https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000Pqos

After installation just append “/apex/vfgenerator__codegenerator” in URL.






Object Name : Valid object API name (include namespace if any)
Record Type : Record type Id of object selected in Object Name
Type of Page :
  1. Edit : Code will be generated for the edit page of the object (according to “Record Type” layout if selected any).
  2. Detail : Code will be generated for the detail page of the object (according to “Record Type” layout if selected any)
  3. Custom Detail : Code will be generated for detail page according to the fields selected from UI
  4. Custom Edit : Code will be generated for edit page according to the fields selected from UI

In the above screen I have selected “Edit” as the type of page and “Account” in object, also provided my email. When I click “Generate Code” it displays like this



Just copy the code and paste it in new visualforce page. For get full formatted code enter your email address in given field.

Now lets try creating some custom visualforce page. Select “Custom Edit” in “Type of Page” and “Account” in “Object Name”. It will display a section “Select Fields”. Click on “Display Fields”, it will display all fields which are up datable by present user.





Tuesday, 31 March 2015

JavasScript Remoting using VisualForce and Apex (SalesForce)

Remoting allows us to perform almost any apex logic via Javascript.

Let's consider Javascript remoting as similar as AJAX call done in normal websites built using PHP, ASP.NET or so.

So, let's see how we can do this.

In this demo, I have attempted to create a drop-down list having
options created dynamically based on the data from a custom object
and then calling a javascript function(at onchange event) which
refers to a remote action of the controller positionController written in apex.


The VisualForce Page Contains the code as below

<apex:page controller="poistionController" showHeader="false">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
//Function that calls the controller written in Apex and returns the required data.

function selectPosition(id){
 
var pos = document.getElementById(id).value;

    poistionController.getPositionDetails( pos,

    function(result, event){

         if (event.status && event.result) {

         // Creating the HTML content based on

         //the data returned from positionController and getPositionDetails method.

              var html = '<table>';

           html = html + '<tr><td>Position Name :</td>';

            html = html + '<td>'+event.result[0].Name+'</td></tr>';

            html = html + '<tr><td>Min Pay :</td>';

            html = html + '<td>'+'$'+event.result[0].Min_Pay__c+'</td></tr>';

            html = html + '<tr><td>Max Pay :</td>';

            html = html + '<td>'+'$'+event.result[0].Max_Pay__c+'</td></tr>';

            html = html + '</table>';

            $('#positionDetails').html(html);

      } else {

             alert(event.message);

      }

}, {escape:true});

}

 </script>

   <div align="center" width="550px">

      <h1>Congratulations</h1>

      This is my new Page : <b>VisualForce & Apex !!!</b><br />
  <apex:outputText value="Your maximum salary could be AT MAXIMUM {!pos.Max_Pay__c}"/>

      </b>

      <apex:form >

        <apex:selectList value="{!pos}" multiselect="false" size="1" id="positionTitle" onchange="selectPosition('{!$component.positionTitle}');">

         <apex:selectOptions value="{!options}"/>

         </apex:selectList>

      </apex:form>

   </div>

   <div id="positionDetails" align="center">

         <!-- Position details is displayed here. -->

   </div>

</apex:page>

 positionController contains codes as below.

global with sharing class poistionController {

      public Position__c pos{get;set;}
      public List<Position__c> title{get;set;}
      public List<Position__c> positions{get;set;}

      public poistionController() {

         pos = [select Max_Pay__c from Position__c where Name = 'Sr. Java Developer'];
      }
       /**

      * Method that creates the select option dynamically.

      **/

      public List<SelectOption> getOptions() {

          List<SelectOption> options = new List<SelectOption>();
          title = [select Position__c.Name from Position__c];
         //Creating an NULL option.
         options.add(new SelectOption('none','--Select--'));
         for( Position__c a :title ){

            options.add(new SelectOption(a.Name,a.Name));
         }
         return options;
      }

      /**

      * Remote action involved with Javascript remoting and is made global

      **/

      @RemoteAction
      global static Position__c[] getPositionDetails(String pos) {
          return [select Position__c.Name, Max_Pay__c, Min_Pay__c, Days_Open__c from Position__c WHERE                         Position__c.Name =: pos];

      }

}

In the above code for positionController, method named getOptions() is involved with creating options for drop-down list and getPositionDetails() is involved with fetching position details and acts as the remote action and is made global.

In the VisualForce page the javascript method selectPosition() refers to the remote action getPositionDetails() of positionController.

The portion of selectPosition() method in grey and italics is used for javascript remoting.

escape specifies whether the response from the Apex method will be escaped or not.

By default it's TRUE.

The syntax for javascript remoting is as given below,

[<namespace>.]<controller>.<method>([params...,] <callbackFunction>(result, event) {

     // callback function logic

}, {escape:true});

Here, namespace is optional and is required if the class comes from an installed package.

In the controller, the Apex method declaration must be preceded with @RemoteAction annotation as shown below.

@RemoteAction

global static String methodName(String objectName) {

   //Logic written in Apex.

}

The methods with @RemoteAction annotation must be global and static.

The response from the server is in JSON format.

For this demo, it's something like as given below.

[{"type":"rpc","tid":3,"action":"poistionController",

"method":"getPositionDetails","result":{"serId":1,

"value":[{"serId":2, "value":{"Days_Open__c":142,"Name":"Sr. PHP Developer",

"Max_Pay__c":2500000.00,"Id":"a0190000002RNUJAA4", "Min_Pay__c":1500000.00}}]}}]

Enable Google Talk Sidebar in Salesforce


Let's see how we can enable the google talk sidebar component in Salesforce.

Go to http://www.google.com/a to sign up your domain for Google apps.
Log in to your salesforce account.
Click on the user menu (Your name at top-right of the salesforce page.) > Setup > Administration Setup > Google Apps > Settings

Click on "Edit" in the "Configure Google Apps Domain" section and fill up the "Google App Administrative Contacts" and your "Google Apps Domain" input fields. Now click save.
Now, in the "Activate Google Apps Services" section click on "Edit" link next to "Google Talk Sidebar Component".

Select the two checkboxes "Add the Google Talk component to salesforce.com sidebar." & "I agree to the salesforce.com Terms of Use for Google Apps."


Similarly, we can enable other Google Apps like Gmail, Google Docs etc. in salesforce.

These are some of the already available features in salesforce.com and we need to enable them for use. :-)

Uploading a Document in Salesforce Using Visualforce Page


Some times we need to upload files such as image files,word document etc, and also need to use its reference to use it in our VF page .

In that case we have to follow these steps

In that case we have to follow these steps

Step 1: Click on the document Tab

Step 2: Select the file from your local system to upload & also choose the folder in which you want to save it

Step 3: Keep its reference as a record to use it, if you want to access it directly form record

Instead of following these above steps, we can do these in only one visual-force page.

In this tip we will be understanding the procedure to upload a file into "Documents" using a Visual-force Page.

Hence, this topic would only cover uploading a file to "Documents" under a folder you desire.

<apex:inputfile>
 is the tag that is used to upload a file.



Sample Code

 FileUpload : Sample Visual-force page


 <apex:page controller="FileUploadController" showHeader="true" standardStylesheets="false">

<head>

<script type="text/javascript">


function SelectFile( fileUrl )

{

// window.opener.SetUrl( url, width, height, alt);

parent.SetUrl( fileUrl ) ;

}

</script>

</head>

<apex:messages />

<apex:form >

<apex:inputFile value="{!document.body}" filename="{!document.name}"/>

<br />

<apex:commandButton value="save" action="{!doUpload}" />

</apex:form>

<apex:pageBlock rendered="{!hasImage}" >

<img src="{!url}" width="200" height="160" />

<script>

this.onload = function() {

SelectFile('{!url}');

}

</script>

</apex:pageBlock>

</apex:page>




FileUploadController: Apex Class


 public class FileUploadController{

public Document document {get; set;}

public String url {get; set;}

public boolean hasImage {get; set;}



public FileUpload() {

hasImage = false;

document = new document();

}


 public PageReference doUpload() {

if (document.body != null) {

System.debug('@@@@@@@@ document:' + document.name);

 if (document.name != null) {

System.debug('@@@@@@@@ doSave');

 Document d = document;

System.debug(document);

System.debug('@@@@@@@@ document name: '+d.name);

System.debug(d);



d.folderid = UserInfo.getUserId(); //store in Personal Documents


 /*
d.folderid
 = 'any other id you want here'; // Fetch Id dynamically by using [Select Id from Folder where Name='My Images'].*/

System.debug('@@@@@@@@ document folder id: '+d.folderid);

d.IsPublic = true;

 try {

insert d;

url = DocumentUtil.getInstance().getURL(d);

hasImage = true;

} catch (Exception e) {

ApexPages.addMessages(e);

url = '';

}

 d.body = null;

 System.debug('@@@@@@@@ document object id: '+d.id);

String url = DocumentUtil.getInstance(d).getURL();

System.debug('######## document content type: '+d.type);

}

 }

 PageReference page = new PageReference('/apex/FileUpload');

//page.setRedirect(true);

return page;

}

 static testmethod void testFileUpload() {

FileUpload fu = new FileUpload();

fu.doUpload();

 fu.document.Name = 'test1';

fu.document.Body = Blob.valueOf('test1');

 fu.doUpload();

 }

 }

How to Pass ID in Visualforce Pages

Apex Controller:-

public class Teamlist {
  
    
    public ApexPages.StandardSetController setTeam {
        get {
            if(setTeam == null) {
                setTeam = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id, name from Team__c]));
            }
            return setTeam;
        }
        set;
    }
    
     public List<Team__c> getTeams() {
         return (List<Team__c>) setTeam.getRecords();
       }  
         
    public PageReference Go() {
      Id id = System.currentPageReference().getParameters().get('id');
      PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
                return nextpage;
    }
  }

VisualForce Page:-

<apex:page controller="Teamlist" showHeader="false" title="false"> 
  <apex:form >
   <apex:tabPanel switchType="client" selectedTab="TabDetails" tabClass="activetab" inactiveTabClass="inactivetab">
        <apex:tab label="TEAM">
            <apex:pageBlock title="TEAMLIST">
                <apex:pageBlockTable value="{!teams}" var="t">
                    <apex:column headerValue="TEAM NAME">
                       <apex:outputPanel >
                            <apex:commandLink action="{!Go}">
                               {!t.name}<apex:param name="id" value="{!t.id}"/>
                            </apex:commandLink>
                       </apex:outputPanel>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:tab>
   </apex:tabPanel>
  </apex:form>
</apex:page>



Here is a visualforce page containing a list of teams. What we want is after clicking a particular team name, it will go to a page where the details are displayed of that corresponding team. Here we are retrieving the team id using <apex:param name="id" value="{!t.id}"/> within commandLink where we defined the action.
Then we can observe that we defined that function in the apex controller for getting that id by System.currentPageReference().getParameters().get('id'); After that it is referenced in a different page with that id. It may be simple,but as a beginner I think it is an important thing to know.