Thursday, July 17, 2014

How to compare old field value with the New field value in Salesforce?

How to compare old field value with the New field value in Salesforce?


Here you can compare the values with  trigger.oldMap . Here is the sample example on contact email field.

trigger Email_Check_On_Contact on Contact (before update) {
  Map<Id,Contact> o = new Map<Id,Contact>();
    o = trigger.oldMap;
    for(Contact newcont: trigger.new)
    {
      
        if(newcont.Email != o.get(newcont.Id).Email)
        {
            newcont.Email.addError('Email cannot be changed');
        }
    }
}



save image






Wednesday, July 16, 2014

How to view Force.com IDE log?

How to view Force.com IDE log?








Tuesday, July 15, 2014

How to use static resource in image formula field in Salesforce?

How to use static resource in image formula field in Salesforce? 


Sample formula:

IMAGE( '/resource/sfdcsrini__Dial', 'Dial');

here "sfdcsrini__Dial" is the static resource name for the image.





Monday, July 14, 2014

Sales Process flow

Sales Process flow 

Sales Process flow starts from Leads i.e.


Creation of Leads --> Conversion of Leads once qualified (Potential Identified) --> Converting Lead to Account, Contact & Opportunity for New customer Or only Opp for an existing customer --> Update & maintaining the Opportunity details (Product, visits, closing date, etc) as per the customer follow up --> closing the Opp after the logical conclusion of the order.
Our Sales process flows through various stages in Sales funnel starting from Prospecting/design Assit --> Budget Price --> RFQ (Request for Quote) --> Tender/Proposal --> Negotiation/Review --> Order Agreed --> Closing of Opp (Won / Lost / No Bid / Cancelled).


Note: It changes from one organization to another.





How to find the deployment status in Salesforce?

How to find the deployment status in Salesforce? 


Note: that this page shows deployments started via the deploy() metadata API, which includes Force.com IDE, Force.com Migration Tool, but not change sets.







Sunday, July 13, 2014

How to Read/Create record types in Apex test class?

How to Read/Create record types in Apex test class?

We have some important consideration while creating test data in our test classes.
So let say if we need to create a record based on the record type id , what we do normally , we query on record type object based on SobjectType and the record type Name.

for example :
let say we have a Account Record Types A & B Not if we need to create a Account Record with record type A or B . We normally query like this .
RecordType rt = [select id,Name from RecordType where SobjectType='Account' and Name='A' Limit 1];
And now use this value further while creating the Account Record.
Account acc = new Account(Name='Test' , recordTypeId=rt.id);

To avoid this query in test class we can the same in some other manner 
Schema.DescribeSObjectResult cfrSchema = Schema.SObjectType.Account; 
Map<String,Schema.RecordTypeInfo> AccountRecordTypeInfo = cfrSchema.getRecordTypeInfosByName();
Now to get the recordTypeId we will have to use a method getRecordTypeId.
Id rtId = AccountRecordTypeInfo .get('A').getRecordTypeId(),
Now Use can insert Account Record like

Account Acc = new Account(Name='test',recordtypeid=AccountRecordTypeInfo .get('A').getRecordTypeId());
insert Acc;







Saturday, July 12, 2014

Salesforce Custom objects and fields Limitation

Salesforce Custom objects and fields Limitation


Custom Objects and fields limitation is based on the Salesforce Edition (Group, Professional, Enterprise and Unlimited Editions)

Salesforce.com Editions
Group Edition
Professional Edition
Enterprise Edition
Unlimited Edition
Developer Edition
Total Custom Fields per Object
100
100
500
800
500
Total Custom Objects
50
50
200
2,000
400





Friday, July 11, 2014

Setting up Single Sign-On in Salesforce.

Setting up Single Sign-On in Salesforce.

Hi,

Here is the video to setup a signle sign on salesforce and the documentation is available in https://developer.salesforce.com/page/How_to_Implement_Single_Sign-On_with_Force.com


Is it possible to mass update users licenses in Salesforce?

Is it possible to mass update users licenses in Salesforce

It can possible mass update users licences in salesforce with Data loader or On-Demand Tools.To simply update the User ProfileID. When you mass update users ProfileID the underlying User License gets updated.

Please refer user object details





Thursday, July 10, 2014

How to execute the batch apex class using developer console?

How to execute the batch apex class using developer console?

Example:

Batch Apex Class:
global class accountList implements Database.Batchable<Sobject> {

global Database.querylocator start(Database.BatchableContext BC) {
return Database.getQueryLocator([select Id, Name from Account]);
}
global void execute(Database.BatchableContext BC, list<Account> scope) {
return Database.getQueryLocator(query);
}
global void finish(Database.BatchableContext BC) {
}
}

Execute the Batch Apex Class using Developer Console using below,

accountList objTest = new accountList();
Database.executebatch(objTest);




Wednesday, July 9, 2014

How to query This Fiscal and Last Fiscal Year opportunities?

How to query This Fiscal and Last Fiscal Year opportunities.

You can use THIS FISCAL YEAR and LAST FISCAL YEAR date values to get the opportunities.


list<opportunity> opplist =[SELECT Id,closedate FROM Opportunity WHERE CloseDate = THIS_FISCAL_YEAR limit 10];
system.debug('opplist-->'+opplist);

list<opportunity> opplist2 =[SELECT Id,closedate FROM Opportunity WHERE CloseDate = LAST_FISCAL_YEAR limit 10];
system.debug('opplist2-->'+opplist2); 




Tuesday, July 8, 2014

How to Use Salesforce Static Resource as a Dynamically?

How to Use Salesforce Static Resource as a Dynamically

Let’s suppose we have an archive in static resource with name "Contact" and you want to use this static resource on a page that displays Contact Photos dynamically. Assumption is that the images are stored with same name as product codes.
Code:

//Declare an apex variable which gets the Contact code from an apex property

<img alt="" src="{!URLFOR($Resource.Products,contact_photo)}')" />




Monday, July 7, 2014

Passing parameters with Command Link

Passing parameters with Command Link

create a command link and pass arguements. In the apex class you can get the parameters and use the value in your code.

Visual Force Page:

<apex:page controller="showCammand"> 
<apex:form> 
<apex:commandLink id="commandLink" action="{!displayName}" value="Show my name">
 <apex:param name="Name" value="myName"/> 
</apex:commandLink> 
<br/> My name: {!name} 
</apex:form> 
</apex:page>


Apex Class:

public class showCammand()
{
public String name {get; set;}
public void displayName()
{
name = ApexPages.CurrentPage().getParameters().get('Name');
}
}







Sunday, July 6, 2014

What is the Visualforce Page Size?

 What is the Visualforce Page Size

A single page can hold up to 1 MB of text, or approximately 1,000,000 characters



Saturday, July 5, 2014

How to get the query parameters in visualforce page?

How to get the query parameters in visualforce page

We can get the Query Parameters in Visualforce page using {!$CurrentPage.parameters.QUERYPARAMETER NAME}
For Instance:
https://Salesforce_instance/apex/VFPage?Id=001D000000IRt53&CaseId=003D000000T6bIE
Here we can get the ID and CASEID value from Query Paramerts to VF page like
{!$CurrentPage.parameters.Id} – ID VALUE (001D000000IRt53)
{!$CurrentPage.parameters.CaseId} – CASEID VALUE (003D000000T6bIE) 


Friday, July 4, 2014

How to check whether a record has been locked in the Approval Process?

 How to check whether a record has been locked in the Approval Process?

Simple Steps:

Step1 : Create a field (say FLAG) of type Checkbox. Set the default value to UNCHECKED.

Step2: In your Approval Process in the INITIAL SUBMISSION Action , create a Field Update. Update the FLAG to TRUE.

Step3: In your FINAL APPROVAL and REJECTION Actions, create a Field Update. Update the FLAG back to FALSE.

Step4: And done!!!! You can now find whether a record has been locked simply by checking the FLAG value. Be it in your Apex Class or Visualforce Page.





Thursday, July 3, 2014

Date and Number Format in Visualforce Page.

Date and Number Format in Visualforce Page.


Hi,
Here is the example of Date and Number Format in Visualforce Page.

VF Page:
<apex:page title="Date and Number Formatting in Visualforce Page">
<style>
.tableContent {
border: 1px solid green;
font: 12px, Verdana;
}
.tableHeader {
background-color: green;
font: 16px, Verdana;
color: white;
}
.bold {
font-weight: bold;
}
</style>
<table border="0" cellspacing="2" cellpadding="6" class="tableContent">
<tr class="tableHeader">
<th>
    Format
</th>
<th>
    Input
</th>
<th>
    Output
</th>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, date, short}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!NOW()}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, date, short}">
        <apex:param value="{!NOW()}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, date, medium}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!NOW()}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, date, medium}">
        <apex:param value="{!NOW()}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, date, long}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!NOW()}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, date, long}">
        <apex:param value="{!NOW()}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, date, full}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!NOW()}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, date, full}">
        <apex:param value="{!NOW()}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, date, yyyy-mm-dd hh:mm:ss a}" styleClass="bold"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!NOW()}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, date, yyyy-MMM-dd hh:mm:ss a z}">
        <apex:param value="{!NOW()}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, number, integer}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!VALUE('123.456')}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, number, integer}">
        <apex:param value="{!VALUE('123.456')}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, number, currency}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!VALUE('123.456')}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, number, currency}">
        <apex:param value="{!VALUE('123.456')}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, number, percent}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!VALUE('0.5')}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, number, percent}">
        <apex:param value="{!VALUE('0.5')}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, number, 0000.0}" styleClass="bold"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!VALUE('123.456')}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, number, 0000.0}">
        <apex:param value="{!VALUE('123.456')}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, number, ####.#}" styleClass="bold"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!VALUE('123.456')}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, number, ####.#}">
        <apex:param value="{!VALUE('123.456')}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, number, 0.0000}" styleClass="bold"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!VALUE('123.456')}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, number, 0.0000}">
        <apex:param value="{!VALUE('123.456')}"></apex:param>
    </apex:outputtext>
</td>
</tr>
<tr>
<td>
    <apex:outputtext value="{0, number, #.####}" styleClass="bold"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{!VALUE('123.456')}"></apex:outputtext>
</td>
<td>
    <apex:outputtext value="{0, number, #.####}">
        <apex:param value="{!VALUE('123.456')}"></apex:param>
    </apex:outputtext>
</td>
</tr>
</table>
</apex:page>


Output:





Wednesday, July 2, 2014

How to implement “Cancel” functionality in a VisualForce Page?

 How to implement “Cancel” functionality in a VisualForce Page?


Apex Class:


public class sampleExtension {
  ApexPages.standardController std = null;
  public sampleExtension(ApexPages.standardController sc)  {
    std = sc;
  }
  public PageReference doCancel()  {
    return std.cancel();
  }
}

VisualForce Page:
Note: this doesn't necessarily take you to the list view, it’ll return you to the last page you were viewing before going to the VF page.

Reference: 





Tuesday, July 1, 2014

What is Maximum view state size limit exceeded in Salesforce?

Error : Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 410.891KB.  


Step 1:
This will occurs when the variable is u declared as a public .So try to declare this variables as transient. Because this transient keyword used to declare instance variable that cannot be saved.

Step 2:
Open the view state and check which variable it taking the kilobytes, see if you can set that variable to null after rendering the page.

You have to enable view state from your personal information if its already not enabled.
If you edit your profile, there are two checkboxes – “development mode” and “show view state in development mode”.  If you check both of these, you will have access to the view state inspector.  However, if you are already exceeding the view state it may not be much help – you might need to reduce it before you can see it properly if you get  my meaning.

Step 3:
Example:
You will be using a variable to hold file data like this.
VF Page:

In Apex class:
public blob file{get; set;}
Use transient keyword before blob data type. like below,
public transient blob file{get; set;}
The transient keyword gives persistency in the VF page..

For more information please refer to the link:

How to enable view state in Salesforce
http://wiki.developerforce.com/page/An_Introduction_to_Visualforce_View_State
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_transient.htm
http://www.salesforce.com/us/developer/docs/pages/Content/pages_best_practices_performance.htm




 
| ,