Monday 25 November 2013

How to Build A Wizard in Salesforce

Hi Folks,
After getting so many discussion threads over the same topic. I came up with solution of the problem.
Problems:
Type1: Facing issues of passing values to Controller while redirecting to other page when controller is common.
Type2: Either value get passed properly without successful redirection or successful redirection without successful passing value to controller.
Here is the Code snippets:

Page1 : In this page we are trying to pass parameters from page to controller through two ways one is as hidden variable & other one is publicly exposed property

 
  
    
  
  
      
        
       
                
          Exposed Value:          
          

      
             
  

Page2 :



        
      
      
          Hidden Value: 
          
Exposed Value: 
          
 
      
  

Common Controller:
/*
* Author : Sandeep Singhal
* Purpose : This class is common controller between both pages
*/
public Class CommonController{

    // Constructor
    public CommonController()
    {
        
    }
    // Public Properties
    public String valueHoldertExt{get;set;}
    public String valueHolderHidden{get;set;}
    
    // To go to next page mantaining values of controller
    public pageReference goToNextPage()
    {
        PageReference pgRef =  new PageReference('/apex/Screen2');
        return pgRef ;
    }
    
    // To go to Previous page mantaining values of controller
    public pageReference goToPreviousPage()
    {
        PageReference pgRef =  new PageReference('/apex/Screen1');
        return pgRef ;
    }
}
So let's test the functionality:
From page 1, I am passing a hidden value 'sandeep' (refer code of page1) & 'Test1' in inputText field & click on 'Next Page' button. After clicking on'Next Page' button on page1 gets redirected to page2 but values are maintained.(Note: URL is not getting changed. This is a property of salesforce redirection in wizard).)

Here is Page2 if we change value in input text & click on 'Previous Page' button this new value will be available on Page1.
                                           
Here we can setup a complete wizard. 

Tuesday 15 October 2013

DMLOption Usage : How to control Email Notification On Case Insertion

Hi Folks,

Today I would like to present an implementation so you get some control over UI feature from Apex. Generally when we create case, an option is given in order to send email notification of recorded case but while inserting case from apex there is not such property is available from Apex on case object to control email notification.

There is a new way for getting this problem resolved. This is a salesforce option which is called DMLOption.


/* Creating a instance of DMLOPTION entity */
Database.DMLOptions DmlOpt = new Database.DMLOptions();
DmlOpt.EmailHeader.triggerAutoResponseEmail = true;

/* creating instance of Contact */
Contact testContact = new Contact();
testContact.email = 'sksworld10@gmail.com';
testContact.lastName = 'testName' ;
insert testContact  ;

/* creating instance of Case */
Case testCase = new Case();
testCase.status = 'New';
testCase.origin = 'Phone';
testCase.ContactId = testContact.id ; 

/* Inserting Case with Data base method so we can apply entity we created above */
database.insert(testCase, DmlOpt);
So since next time you can enjoy controlling email notifications with Apex.

Saturday 7 September 2013

How to Send SMS on Mobile from Salesforce

Hi  Folks,

Today I brought up a very new type of implementation in Salesforce. We integrate Communication API and Salesforce APIs.
We can control our text/voice communication from few lines of code in Salesforce. I thought the same and made it possible by integrating SALESFORCE with TWILIO (one of the best cloud communication third party system).

Here is a way I followed to achieve to it: 

First of all we need to set up ANT to get some resource pool in our Salesforce from Twilio. You may set up ANT by following steps : 

Step 1 Download apache-ant-1.8.2-bin from Web.
Step 2 Install jdk1.6.0_25 or higher version.
Step 3 Go to run command use command sysdm.cpl press "advanced" tab then press "environment variable" tab then press on tab "New", create two variable ANT_HOME , JAVA_HOME and PATH 
ANT_HOME D: \apache-ant-1.8.2-bin\apache-ant-1.8.2 (if your ant folder is in D- drive)                    
JAVA_HOME  C:\Program Files\Java\jdk1.6.0_25 (give path of jdk)
PATH %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\ProgramFiles\Java\jdk1.6.0_25\jre\bin;D:\apache-ant-1.8.2-bin\apache-ant-1.8.2\bin;
(if path variable is alreadyavailable then append this also other wise create new Path variable)

Step 4. Now login in your Salesforce org and navigate Set up>-App Setup>Develop > Tool> force.com Migration Tool download this and pick one file "ant-salesforce.jar" and put it in lib folder of Apache( where we have ANT setup).

Step 5. We need to import all required classes of Twilio prepared fro Salesforce we need to click here  https://github.com/twilio/twilio-salesforce  and download one folder from this link and unzip it. From unzipped folder navigating nested folder and in "install" folder we will get some build files.

Step 6. Now we need to open command prompt and need to write path of folder where we have build.property and build.xml file  as below :-
Step 7. When Build gets started run below message we will get ( as confirmation that we have downloaded all files from Twilio in to Salesforce).

Step 8. Here you can find in org that Twilio classes have been imported ( just to check of process Completion)



Step 9. My Customization around this package.
A) Custom Setting Setup
When we get library files along with it one custom setting also get configured in org automatically so we need to manage this custom setting with some values :
ACCOUNT_SID, AUTH_TOKEN & Sender's Phone number (for these values we need to create a trail account in Twilio site and then we will get these three parameters).we will keep this information in custom setting.

B) We need to create some record on contact object for this we have created a new field Is_RegisteredTwilioUser = true other then this we need to put Mobile number with ISD code (e.g. INDIA then +91 should be prefixed).
Note : This number should be verified from your Twilio account as below :

Now time to come on screen I developed to send SMS to contacts

(C) Customization to create a screen from where we can manage communication (Text SMS)
Visualforce Page :

Apex Class :
public with sharing class TwilioCloudCommunicationClass {

// Public Properties
public String SelectedMobileNumber{get;set;}
public String OtherMobileNumber{get;set;}
public String textMessage{get;set;}

// Default construtor
public TwilioCloudCommunicationClass()
{
    SelectedMobileNumber  = '' ;
    OtherMobileNumber = '' ;
}

Public List getPersonList()
{
    Try{
        List localList = new List();
        localList.add(new SelectOption('' , '--Select--'));
        for(contact cont : [select Name,MobilePhone from contact where TwilioRegisteredUser__c = true ])
        {
            localList.add(new SelectOption(cont.MobilePhone , cont.Name));          
        }      
        localList.add(new SelectOption('other' , 'Other'));
        return localList ;
    }
    catch(Exception e)
    {
        ApexPages.addMessages(e);      
        return null;
    }
}

public void SendSMS()
{
    Try{      
        SelectedMobileNumber = (SelectedMobileNumber == '')? OtherMobileNumber:SelectedMobileNumber ;
        if(SelectedMobileNumber != '')
        {
            List AdminInfo = TwilioConfig__c.getall().values();
            String ACCOUNT_SID = '';
            String AUTH_TOKEN  = '' ;            
            String SenderMobileNumber = '' ;
            // Informaton getting from custom setting
            if(AdminInfo.size()>0)
            {          
                ACCOUNT_SID             = AdminInfo[0].AccountSid__c;
                AUTH_TOKEN              = AdminInfo[0].AuthToken__c;                
                SenderMobileNumber      = AdminInfo[0].Admin_Mobile_Number__c;    
            }            
            TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
           
            Map properties = new Map {
                        'To'   => SelectedMobileNumber ,
                        'From' => SenderMobileNumber,
                        'Body' => textMessage
                };
            TwilioSMS message = client.getAccount().getSmsMessages().create(properties);
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Message has been sent'));
        }
        else
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'Pelase provide valid Mobile Number '));
        }
    }catch(Exception e )
    {
        ApexPages.addMessages(e);      
        return ;
    }  
}

}

Tuesday 3 September 2013

How to override View page of SObject based on Record Type

Hi Folks,

Today I brought up very small and useful trick for overriding View page of s-object based on record type.

Lets say we have an Opportunity Object with record type 'JapanType' & 'USType' and we need to show 'JapanType' with standard layout while 'USType' with Custom Screen.

It is not possible by any customization in salesforce but we can achieve it with small script over the page: 

  

SO if even we have overridden view page of opportunity with VF page but if that record type is of 'JapanType' page gets it's standard layout.

Thursday 22 August 2013

Salesforce winter'14 Release

Hi friends,

Wait is over !!

Salesforce winter'14 Notes has been released.

Please click here
Salesforce winter'14 Notes

with regards...
Sandeep

Saturday 17 August 2013

How to Rename Home Tab in Salesforce

Hi Folks,

On force.com community I was asked about renaming Home Tab in Salesforce. I have figured it out using home page component. Home page component is very useful tool for applying customization over standard layouts up to some extent.
Here is Home Tab normally




In order to implement this I have just created a Home page component and put it on requested home page layout. Here is piece of code


After Applying this Home page component, Home tab would looking like below:


Thanks for reading this article.

Sunday 4 August 2013

How to send Email from Apex code with controlling 'From Address' & Sender's Name Dynamically

Hi friends,

Today I came up with one interesting thing to share with you. Generally we send emails from Salesforce using following ways :-
1. Apex Code
2. Email Alerts
3. Outbound messaging etc.

In all of these ways we normally set 'To'/'Cc'/'Bcc' but have you thought how to control 'From address of email'? what to do if we need to send email displaying any other email address in 'from' part instead of sender's email address. Here is one Salesforce feature to get rid of this problem that is "Organization-Wide Email Addresses".


In above screen shot you just need to
1. Navigate Setup -> Email Administration ->  Organization-Wide Email Addresses
2. Click on Add button.
3. Enter email Id and display name of sender.
4. In order to complete this process you need to get verified email id you are putting here ( in this example it is 'testuser@gmail.com').

Now it is ready for use. Let's see how we can use it in Apex code side:-

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
string body = 'Hi ';
String[] toAddresses = new String[] {'sksworld10@gmail.com'}; 
mail.setToAddresses(toAddresses);
mail.setSubject('Test Subject');  
mail.setSaveAsActivity(false);  
for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress]) 
{
 if(owa.Address.contains('testuser')) 
  mail.setOrgWideEmailAddressId(owa.id); 
}
mail.setHtmlBody(body);  
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


Here you can notice that we can control 'From address' in sending email.

Thanks for reading this article.

Monday 24 June 2013

Page Views Counter widget in salesforce

Hi All,
Today, I am going to show you an application of cookies in context of salesforce. I think, at many discussion boards and blog areas you have seen number of page views or visitor counter on top of that if not you can see it on this current blog in right panel. So what I implemented is same counter widget in salesforce using cookies. Cookies is a API which helps you to let your browser remember many things which you don't want. So here I have composed it with in VF page, Apex class & to expose it I have used force.con site feature.




Please Click on below link to get Demo.
Demo Link

 Visualforce Page:

  
      
          You are visitor number : {!visitorNumber}
      
  

Apex Class:
public class PageviewCouterUtilClass {
    public String visitorNumber{get;private set;}
    public PageviewCouterUtilClass () {
        Cookie PageCounter = ApexPages.currentPage().getCookies().get('PageCounterCookie');
         
        // User is accessing page first time       
        if (PageCounter == null) {
            PageCounter = new Cookie('PageCounterCookie','1',null,-1,false);// create a new cookie 'PageCounterCookie', an initial value : '1', path :  'null', maxAge  : '-1'and isSecure : 'false'.
        } else {        
            Integer visitorNumber = Integer.valueOf(PageCounter.getValue());
            PageCounter = new Cookie('PageCounterCookie', String.valueOf(visitorNumber+1),null,-1,false);
        }    
        // Set the new cookie for the page
        ApexPages.currentPage().setCookies(new Cookie[]{PageCounter});  
        if(PageCounter == null) 
        {
            visitorNumber = '0';
        }   
        else
        {
            visitorNumber =  PageCounter.getValue();
        }     
    }
}

Here is a limitation of loosing counter in case of deleting cookies in this case counter will be reset. To avoid this problem you can store this counter value in your salesforce org like custom setting.

Thanks 
Sandeep

Sunday 9 June 2013

List of Components available in Change Set for Migration

Hi Friends, "Is it possible to migrate this component through Change Set or not?" such type of queries are ofently found in discussion & forums.To check this out we need to create sample change set(which is not possible in free Developer Org.) it takes time. So for answering all these queries at once I have listed here all components which are possible to migrate through change set in Salesforce as below :

Account Owner Sharing Rule Account Territory Sharing Rule Action
Analytic Snapshot Apex Class Apex Sharing Reason
Apex Trigger App Approval Process
Assignment Rule Auth. Provider AutoResponse Rule
Button or Link Call Center Campaign Criteria Based Sharing Rule
Campaign Owner Sharing Rule Case Criteria Based Sharing Rule Case Owner Sharing Rule
Contact Criteria Based Sharing Rule Contact Owner Sharing Rule Custom Data Type
Custom Field Custom Label Custom Object
Custom Object Criteria Based Sharing Rule Custom Object Owner Sharing Rule Custom Report Type
Custom Setting Dashboard Document
Email Template Escalation Rule External Data Source
Field Set Flow Folder
Group Home Page Component Home Page Layout
Language Translation Lead Criteria Based Sharing Rule Lead Owner Sharing Rule
Letterhead List View Opportunity Criteria Based Sharing Rule
Opportunity Owner Sharing Rule Page Layout Permission Set
Queue Record Type Remote Site
Report Role S-Control
Send Action Static Resource Tab
Territory Validation Rule Visualforce Component
Visualforce Page Workflow Email Alert Workflow Field Update
Workflow Outbound Message Workflow Rule Workflow Task
Zone

List is updated as per summer'13 Release. I will update this list in next salesforce releases.

Thursday 6 June 2013

How to fetch Standard Profiles from SOQL

Hi friends today I am going to share one small trick. 
Recently I met with a problem where I need to fetch only standard profiles in SOQL. I went to force.com developer board and some other discussion forums and finally found the work around.

As we all know that there is no such attribute on profile to determine whether it is standard or custom so we can use a concept here that "standard profile gets created along with organization by Salesforce only" so it's created Date time would be same as organization.


Datetime OrgCreatedDateTime = [Select id , createdDate from Orgaization ][0].CreatedDate ;



Now we would like to query profile with same createdDate time.

List<profile> StandardProfiles = new List<profile>();
StandardProfiles = [select id,Name from Profile where createdDate = :OrgCreatedDateTime];

So "StandardProfiles"  is list of all standard profile of our org this is just a work around because I am still worried if a new standard profile gets enabled on demand after creating Org.
Please share your views ahead.

Friday 24 May 2013

Visualforce Page Code Downloader

Hi All,
It's just an idea to provide an option to download code of Visualforce Page in salesforce. I got this idea when I required  to download VF page code to keep backup and there is no option (given by salesforce) to download page code as it is available for Apex Class & Apex Trigger etc.

For this I have created a wizard on which you can;
1. Create a new page.
2. Edit any Existing visualforce Page.
3. Download code of visualforce page.


I am providing an un-managed code  so you can get understand and do any customization:

follow steps:
1.I can get all required code packet in your org just by clicking on this below link:

https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000IGtn

2.You can easily install this package in your org in very easy steps:
3.You need to enable a Tab "VF Page Code Downloader" on your current application.

Thanks
Sandeep


Friday 3 May 2013

The Salesforce.com Summer '13 Release Notes Now Available


Spring gone Summer came with package of many new features in Salesforce.
You can download Release Notes .
Click on this link below to see them: Salesforce Summer '13 Release

Monday 1 April 2013

Salesforce Helptext with Custom Tooltip

Often we need to override native layout in salesforce by custom implementations. In order to go on this way I have explored field-level Help Text Tool-Tip in customize way.


Here is a very simple example to build more understanding over this.

Visualforce Code :
<apex:page standardController="Opportunity">
    <!-- Style Panel Satrts--->
    <style type="text/css">
        .imgclass:hover{
            background-image: url(/img/help/helpOrbs.gif);
            background-repeat: no-repeat;
            width: 16px;
            height: 15px;   
            background-position: right;
       
        }
        .imgclass{
            background-image: url(/img/help/helpOrbs.gif);
            background-repeat: no-repeat;
            width: 16px;
            height: 15px;
        }
    </style>
    <!-- Style Panel Ends--->
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Enter Information">
                <apex:pageblockSectionItem >
                    <apex:outputPanel >
                        <apex:outputlabel value="Enter Opportunity Name"/>                                        
                        <img src="/s.gif" Class="imgclass" title="Please Enter Opportunity Name" />
                    </apex:outputPanel>
                    <apex:inputField value="{!Opportunity.Name}"/>              
                </apex:pageblockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>   
</apex:page>

Share your feedback..

Wednesday 20 March 2013

How To Show Code on Blog

This is very common question for every new on Blogger that "How to show code snippet in proper shape"
Here are four simple steps to do it.

Step 1. Login in your blogger
Step 2. You can keep a backup for your existing template clicking a Restore/Backup Button

Step 3. Open Template in Edit mode as follows:


Step 4. In this you need to add some CSS code as follows:

A) Add following code before </head>
<script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shCore.js" type="text/javascript">
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushDelphi.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushXml.js' type='text/javascript'/>
B) Add following code before</body>

C) Add following code before ]]>
padding: 0px;
 color: #5C5C5C;
}

.dp-highlighter.nogutter ol,
.dp-highlighter.nogutter ol li
{
 list-style: none !important;
 margin-left: 0px !important;
}

.dp-highlighter ol li,
.dp-highlighter .columns div
{
 list-style: decimal-leading-zero; /* better look for others, override cascade from OL */
 list-style-position: outside !important;
 border-left: 3px solid #6CE26C;
 background-color: #F8F8F8;
 color: #5C5C5C;
 padding: 0 3px 0 10px !important;
 margin: 0 !important;
 line-height: 14px;
}

.dp-highlighter.nogutter ol li,
.dp-highlighter.nogutter .columns div
{
 border: 0;
}

.dp-highlighter .columns
{
 background-color: #F8F8F8;
 color: gray;
 overflow: hidden;
 width: 100%;
}

.dp-highlighter .columns div
{
 padding-bottom: 5px;
}

.dp-highlighter ol li.alt
{
 background-color: #FFF;
 color: inherit;
}

.dp-highlighter ol li span
{
 color: black;
 background-color: inherit;
}

/* Adjust some properties when collapsed */

.dp-highlighter.collapsed ol
{
 margin: 0px;
}

.dp-highlighter.collapsed ol li
{
 display: none;
}

/* Additional modifications when in print-view */

.dp-highlighter.printing
{
 border: none;
}

.dp-highlighter.printing .tools
{
 display: none !important;
}

.dp-highlighter.printing li
{
 display: list-item !important;
}

/* Styles for the tools */

.dp-highlighter .tools
{
 padding: 3px 8px 3px 10px;
 font: 9px Verdana, Geneva, Arial, Helvetica, sans-serif;
 color: silver;
 background-color: #f8f8f8;
 padding-bottom: 10px;
 border-left: 3px solid #6CE26C;
}

.dp-highlighter.nogutter .tools
{
 border-left: 0;
}

.dp-highlighter.collapsed .tools
{
 border-bottom: 0;
}

.dp-highlighter .tools a
{
 font-size: 9px;
 color: #a0a0a0;
 background-color: inherit;
 text-decoration: none;
 margin-right: 10px;
}

.dp-highlighter .tools a:hover
{
 color: red;
 background-color: inherit;
 text-decoration: underline;
}

/* About dialog styles */

.dp-about { background-color: #fff; color: #333; margin: 0px; padding: 0px; }
.dp-about table { width: 100%; height: 100%; font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; }
.dp-about td { padding: 10px; vertical-align: top; }
.dp-about .copy { border-bottom: 1px solid #ACA899; height: 95%; }
.dp-about .title { color: red; background-color: inherit; font-weight: bold; }
.dp-about .para { margin: 0 0 4px 0; }
.dp-about .footer { background-color: #ECEADB; color: #333; border-top: 1px solid #fff; text-align: right; }
.dp-about .close { font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; background-color: #ECEADB; color: #333; width: 60px; height: 22px; }

/* Language specific styles */

.dp-highlighter .comment, .dp-highlighter .comments { color: #008200; background-color: inherit; }
.dp-highlighter .string { color: blue; background-color: inherit; }
.dp-highlighter .keyword { color: #069; font-weight: bold; background-color: inherit; }
.dp-highlighter .preprocessor { color: gray; background-color: inherit; }

Now when you write any blog write in compose mode and then hit on HTML mode and  write <pre class="cpp" name="code"></pre>
around the code which you want to show on blog with style.

Special Thanks to Amit Jain for letting me know this information.

Sandeep

Thursday 21 February 2013

How to Plot PageBlock Table using HTML table tags

Hi
In salesforce we can not complete our requirement always using PageBlock Table so we need to use HTML many times. so Here I am giving a way to convert HTML Table code to PageBlockTable.

Lets say if you need to plot this Table then

NameSSIDBank
Bank NameBank CodeAccount No.

Now it's Equivalent PageBlock Table:



VF Page :
 
 
  
   
   
 
Name SSID Bank
Bank Name Bank Code Account No.
Test1 TestId1 Bank Name1 Bank Code1 Account No.
Controller :
Public Class EquvilentTableCode
{
 public List DataList{get;set;}
 public EquvilentTableCode()
 {
 DataList = new List{'a' ,'b'};
 }
}

Thanks for reading.
SalesforceClub on FaceBook

Tuesday 12 February 2013

How To Rewrite ID of Any Record in Salesforce


Recently I came up with a new feature of Spring 13 as you could not set Id field after creating record but now you can.
You can set the Id field on the any Sobjects to IDs of  any other existing record using update DML. Here we will learn how to do this and what are benefits of this feature.
In following example we are creating two new record of Account object. TestAccount1 & TestAccount2.

// Insert both accounts
Account TestAccount1 = new Account(Name='Account1');
insert TestAccount1 ;
Account TestAccount2= new Account(Name='Account2', Industry='Energy');
insert TestAccount2 ; 
// fetching first Account to update
TestAccount1 = [select id,Name,industry from Account where id = : TestAccount1.id ] ;
// Update the first account.
TestAccount2.Id = TestAccount1.Id;
update TestAccount2;
after performing above execution You will find that TestAccount1's industry & Account Name will be updated from TestAccount2 record.

But if we do as below :
TestAccount1 = [select id,Name from Account where id = : TestAccount1.id ] ;
// Update the first account.
TestAccount2.Id = TestAccount1.Id;
update TestAccount2;
then only name will be update from TestAccount2 not industry field.

Thursday 31 January 2013

Spring ‘13 Cloud Trivia

Hi friends,

Spring ‘13 expertise gets over with full of enthusiasm and I have collected all questions and answers for all of who missed the event.

Q: By what name were ‘Connected Apps’ previously known?
A: Remote Access apps

Q: What is the authorization protocol used by Connected Apps?
A: OAuth 2.0

Q: What 4 kinds of code artifact can the Tooling API manage?
A: Apex Classes, Apex Triggers, Visualforce Pages, Visualforce Components

Q: Which other Force.com API allows you to deploy code?
A: The Metadata API

Q: Which new tab was added to the Developer Console?
A: ‘Progress’

Q: Connect in Apex also known as the ___(a)___ API is the native representation of the ___(b)___ API.
A: a. Connect b. Chatter

Q: What VF component attribute allows you to send controller data into your Canvas app?
A: Parameters

Q: What standard field that was formally read only is now writable on update?
A: ID

Q: What are two new object triggers you can create for chatter in Spring 13?
A: CollaborationGroup and CollaborationGroupMember

Q: What does Force.com Canvas use to prevent XHR problems posting back to Salesforce?
A: JavaScript SDK

for more daily updates visit official SalesforceClub to get winner list


Best Regards
Sandeep

Tuesday 29 January 2013

Execute SOQL On Chatter in Salesforce

Today I am providing a piece of code which will introduce a new way to run your simple SOQL on Chatter it self without opening developer console(that might take some time while loading).

To use this tool you just need to keep this trigger code in your org and then you can execute simple SOQL queries as follows.

Step1 : Post a SOQL in chatter on any object in the org.
Step2 : Refresh the screen you will get your result as below.


trigger ChatterAsConsole on FeedItem (after insert)
{   
    if(UtilClass.noOfExecution == 0)
    { 
        String queryString = '';  
        FeedItem post ; 
        for (FeedItem f: trigger.new)
        {  
            Try
            {                 
                //Adding a Text post
                post = new FeedItem();
                post.ParentId = f.ParentId; //eg. Opportunity id, custom objectid
                queryString = f.Body ;
                String idString = '';
                
                for(Sobject s : Database.query(queryString))
                {
                        idString += s.id+', ';
                }        
                if(idString.endsWith(', '))
                    idString = idString.substring(0,idString.length()-2);
                post.Body = idString ;
                UtilClass.noOfExecution ++ ;
                insert post;
            }catch(Exception e)
            {
                post = new FeedItem(ParentId = f.ParentId , Body  = e.getMessage() );
                insert post;
            }
        }
    }
}
Helper Class : 
public Class UtilClass
{
 public static Integer noOfExecution = 0; 
}

This code has its own limitation but you can customize it as per your need.

Best regards
Sandeep









Wednesday 23 January 2013

How to use apex:variable in apex:pageblocktable & apex:repeat

Hi,

This is a cool little script that will tell you how to use apex:variable in visualforce page.
Basically this is nothing but a counter in apex:repeat & apex:pageBlockTable:

    
        
      





In apex:pageBlockTable :

       
             
        
               
    
    
     
     
    
    
 


to get more detail information please Click Here

Thanks
Sandeep


Sunday 20 January 2013

Know Your Salesforce System Status

Hi,

If you are facing some problem while logging your salesforce org. then please visit here to get the reason.
Click Here



Tuesday 1 January 2013

How to get Record Type Id without SOQL

Whenever we would like to fetch data from Database SOQL comes as first option in our mind but it will be added in query consumption limit. Here is a way to do this without any query:

// User need to pass two parameters SObject Type & 
    //RecordType Label ( not Record Type Developer Name)
    public static ID getRecordTypeId(String ObjectType, String RecordTypeLabel)
    { 
      SObject OBJ;
      // Describing Schema
      Schema.SObjectType Res = Schema.getGlobalDescribe().get(ObjectType);
      if (Res != null)
      {
  OBJ = Res.newSObject();
  // Describing Object 
  Schema.DescribeSObjectResult DesRes = OBJ.getSObjectType().getDescribe(); 
  if (DesRes != null)
  {
            Map RecordTypeMap =      DesRes.getRecordTypeInfosByName();
     if (RecordTypeMap != null) 
     {
        Schema.RecordTypeInfo RecordTypeRes = RecordTypeMap.get(RecordTypeLabel);
        if (RecordTypeRes != null) 
        {
           return RecordTypeRes.getRecordTypeId();
        }
      }
   }
        }
 return null;
    } 
Let's say there are two Record Type of Account so we can get Record Type ID of Account Like this
ID RecordTypeId = getRecordTypeId('Account' , 'RecordType1');

Best Regards
Sandeep