Sunday, 15 March 2015

Type of Sandbox in salesforce


Developer Sandbox
Developer sandboxes are special configuration sandboxes intended for coding and testing by a single developer. Multiple users can log into a single Developer sandbox, but their primary purpose is to provide an environment in which changes under active development can be isolated until they’re ready to be shared. Just like Developer Pro sandboxes, Developer sandboxes copy all application and configuration information to the sandbox. Developer sandboxes are limited to 200 MB of test or sample data, which is enough for many development and testing tasks. You can refresh a Developer sandbox once per day.

REFRESH LIMIT    :-  Daily
DATA LIMIT          :-  200MB


Developer Pro Sandbox
The main difference between this and Developer is the amount of data that can be stored.  It also grabs some product data from production.  If those two things are important, use this one.  Otherwise, it's interchangeble with Developer

Developer Pro sandboxes copy all of your production organization's reports, dashboards, price books, products, apps, and customizations under Setup, but exclude all of your organization's standard and custom object records, documents, and attachments. Creating a Developer Pro sandbox can decrease the time it takes to create or refresh a sandbox from several hours to just a few minutes, but it can only include up to 1 GB of data. You can refresh a Developer Pro sandbox once per day

REFRESH LIMIT    :-  Daily
DATA LIMIT          :-  1GB


Partial Copy
Partial Data sandboxes include all of your organization’s metadata and add a selected amount of your production organization's data that you define using a sandbox template. A Partial Data sandbox is a Developer sandbox plus the data you define in a sandbox template. It includes the reports, dashboards, price books, products, apps, and customizations under Setup (including all of your metadata). Additionally, as defined by your sandbox template, Partial Data sandboxes can include your organization's standard and custom object records, documents, and attachments up to 5 GB of data and a maximum of 10,000 records per selected object. A Partial Data sandbox is smaller than a Full sandbox and has a shorter refresh interval. You can refresh a Partial Data sandbox every 5 days.

REFRESH LIMIT    :-  5 Days
DATA LIMIT          :-  5GB


Full Sandbox
Full sandboxes copy your entire production organization and all its data, including standard and custom object records, documents, and attachments. You can refresh a Full sandbox every 29 days.
Sandbox templates allow you to pick specific objects and data to copy to your sandbox, so you can control the size and content of each sandbox. Sandbox templates are only available for Partial Data or Full sandboxes.

REFRESH LIMIT    :-  29 Days
DATA LIMIT          :-  Same as Production





Wednesday, 11 March 2015

how to stop recursive trigger in salesforce

Problem :-  

1) Many Developers face recursive trigger , or recursive update trigger. For example in 'after update' trigger, Developer is performing update operation and this lead to recursive call.

2) You want to write a trigger that creates a new record ; however, that record may then cause another trigger to fire, which in turn causes another to fire, and so on. 

 
Solution :-

you can create a class with a static Boolean variable with default value true. In the trigger, before executing your code keep a check that the variable is true or not. Once you check make the variable false.


 Apex Class with Static Variable

public class ContactTriggerHandler
{
     public static Boolean isFirstTime = true;
}


Trigger Code

trigger ContactTriggers on Contact (after update)
{
    Set<String> accIdSet = new Set<String>(); 
    if(ContactTriggerHandler.isFirstTime)
    {
        ContactTriggerHandler.isFirstTime = false;
         for(Contact conObj : Trigger.New)
  {
            if(conObj.name != 'Test') 
     {
                accIdSet.add(conObj.accountId);
            }
         }
   // any code here
    }
}


Thursday, 5 March 2015

Locking Statements FOR UPDATE

Apex allows you to lock sObject records while they’re being updated in order to prevent race conditions and other thread safety problems. While an sObject record is locked, no other client or user is allowed to make updates either through code or the Salesforce user interface.

Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];

NOTE:-
  1. While the records are locked by a client, the locking client can modify their field values in the database in the same transaction. Other clients have to wait until the transaction completes and the records are no longer locked before being able to update the same records. Other clients can still query the same records while they’re locked.
  2. If you attempt to lock a record currently locked by another client, you will get a QueryException. Similarly, if you attempt to update a record currently locked by another client, you will get a DmlException.
  3. If a client attempts to modify a locked record, the update operation might succeed if the lock gets released within a short amount of time after the update call was made. In this case, it is possible that the updates will
 You can’t use the ORDER BY keywords in any SOQL query that uses locking

Thanks,
Amit Chaudhary

Tuesday, 3 March 2015

How to open a new record inside a console in SubTab by inline visual force page

Include JS in VF page


<apex:includeScript value="/support/console/26.0/integration.js"/>

Write below Java Script code in VF page


<script>

 var preRecordId;
        
        function testOpenSubtab(id, name) 
        {
            preRecordId= id;
            //First find the ID of the primary tab to put the new subtab in

            alert('URL----->'+'{!$CurrentPage.URL}');

             if (sforce.console.isInConsole())
                sforce.console.getEnclosingPrimaryTabId(openSubtab);
             else
              window.top.location.href = '/' + id;
        }
        
        var openSubtab = function openSubtab(result) 
        {
            //Now that we have the primary tab ID, we can open a new subtab in it
            var primaryTabId = result.id;
            
            sforce.console.openSubtab(primaryTabId , '/'+preRecordId , true, 
                preRecordId , null , openSuccess, 'salesforceSubtab');
        };
        
        var openSuccess = function openSuccess(result) 
        {
            //Report whether we succeeded in opening the subtab
            /*
                if (result.success == true) 
                {
                    alert('subtab successfully opened');
                } 
                else 
                {
                    alert('subtab cannot be opened');
                }
            */
        };
</script>


Then use below link to open new record .


 <a href="#" onclick="testOpenSubtab('{!Obj.id}', '{!Obj.id}');return false">{!Obj.customKey}</a>

Sunday, 1 March 2015

How to open a new record inside a console by visual force page ( VF page ):- isInConsole()



Determines if the page is in the Salesforce consoleThis method is only available in API version 22.0 or later.


Solution :-

Include JS in VF page


<apex:includeScript value="/support/console/26.0/integration.js"/>

Write below Java Script code in VF page


<script>

function openTab(id, name) 
{
 if (sforce.console.isInConsole())
  sforce.console.openPrimaryTab(undefined, '/' + id + '?isdtp=vw', true, name);
 else
  window.top.location.href = '/' + id;
}

</script>


Then use below link to open new record .


<a href="#" onclick="openTab('{!Obj.id}''{!Obj.name}'); return false;">{!Obj.customKey}</a>








Sunday, 22 February 2015

Defining Templates with apex:composition , apex:define and apex:insert



<apex:composition> 

An area of a page that includes content from a second template page. Template pages are Visualforce pages that include one or more <apex:insert> components. The <apex:composition> component names the associated template, and provides body for the template's <apex:insert> components with matching <apex:define> components. Any content outside of an <apex:composition> component is not rendered.

<apex:define> 

A template component that provides content for an <apex:insert> component defined in a Visualforce template page.

<apex:insert> 

A template component that declares a named area that must be defined by an <apex:define > component in another Visualforce page. Use this component with the <apex:composition > and  <apex:define > components to share data between multiple pages.


NOTE:-  
1) All templates defined using <apex:composition> must have one or more child <apex:insert> tags. 
2) An <apex:insert> tag indicates to pages that import the template that a section needs a definition. 
3) Any Visualforce page that imports a template using <apex:composition> must use <apex:define> to specify the content of each <apex:insert> section of the template.

The <apex:composition> component fetches the Visualforce template page you created earlier, and the <apex:define> component fills the named holes in that template. You can create multiple pages that use the same component, and just vary the placeholder text

Example 1 :- simple example 

   Composition page

<apex:page>
    <apex:outputText value="(template) This is before the header"/><br/>
    <apex:insert name="header"/><br/>
    <apex:outputText value="(template) This is between the header and body"/><br/>
    <apex:insert name="body"/>
</apex:page>

   Main Page

<apex:page>
    <apex:composition template="composition">
        <apex:define name="header">(page) This is the header of mypage</apex:define>
        <apex:define name="body">(page) This is the body of mypage</apex:define>
    </apex:composition>
</apex:page>

HTML Output

(template) This is before the header<br/>
(page) This is the header of mypage<br/>
(template) This is between the header and body<br/>
(page) This is the body of mypage


Example 2 :- With controller 

Template VF page
<apex:page controller="compositionExample">
    <h1 style="color:Red"><apex:insert name="Title" /></h1>
    <BR> </BR>
    <BR> </BR>
<apex:form >
    <apex:outputLabel value="First Name: " for="nameField"/>
    <apex:inputText id="nameField" value="{!FirstName}"/>
    <br/>        <br/>

    <apex:insert name="LastNameSection" />
    <br/>        <br/>

    <apex:insert name="AgeSection" />
    <br/>        <br/>

    <apex:commandButton action="{!save}" value="Save" id="saveButton"/>
</apex:form>
</apex:page>

Controller class
public class compositionExample{
    public String FirstName{get;set;}
    public String LastName{get;set;}
    public String Age{get;set;}
    public String colorField {get;set;}
    
    public compositionExample()
    {
    }
    
    public PageReference save() {
        return null;
    }
    
}

Import Template in VF page
<apex:page controller="compositionExample">
 <apex:messages />

  <apex:composition template="myCompositionForm">
     <apex:define name="Title">How to write templates In Visual Force page
     </apex:define>
     
    <apex:define name="LastNameSection">
        <apex:outputLabel value="Last Name: " for="LastName"/>
        <apex:inputText id="mealField" value="{!LastName}"/>
    </apex:define>
    
    <apex:define name="AgeSection">
        <apex:outputLabel value="Age: " for="Age"/>
        <apex:inputText id="ageField" value="{!Age}"/>
    </apex:define>
    
       <apex:outputLabel value=" Color: " for="colorField"/>
       <apex:inputText id="colorField" value="{!colorField}"/>
  </apex:composition>

</apex:page>

Example 3 :- Dynamic Template

Template VF page
<apex:page>
    <apex:insert name="name" />
</apex:page>

Controller class with pageReference which will return template Name
public class dynamicComposition {
    public PageReference getmyTemplate() {
        return Page.myTemplatePage;
    }
}

Import Template in Vf page dynamic y.
<apex:page controller="dynamicComposition">
    <apex:composition template="{!myTemplate}">
    <apex:define name="name">
        Hello {!$User.FirstName}
    </apex:define>
    </apex:composition>
</apex:page>


Thanks,

Amit Chaudhary

Monday, 16 February 2015

StartTest and stopTest Method


StartTest() 

Marks the point in your test code when your test actually begins. Use this method when you are testing governor limits.

public static Void startTest()

StopTest() 

Marks the point in your test code when your test ends. Use this method in conjunction with the startTest method.

public static Void stopTest()

NOTE :-

1) The startTest method marks the point in your test code when your test actually begins. Each test method is allowed to call this method only once
2) All of the code before this method should be used to initialize variables, populate data structures, and so on, allowing you to set up everything you need to run your test. 
3) Any code that executes after the call to startTest and before stopTest is assigned a new set of governor limits.
4) The startTest method does not refresh the context of the test: it adds a context to your test. For example, if your class makes 98 SOQL queries before it calls startTest, and the first significant statement after startTest is a DML statement, the program can now make an additional 100 queries. Once stopTest is called, however, the program goes back into the original context, and can only make 2 additional SOQL queries before reaching the limit of 100
5) All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously