Browse Month: June 2014

Avoid recursion of Trigger

Recursive trigger is frequently arising issue in Salesforce triggers. Recursion in trigger means a trigger calling itself again and again. Recursion in trigger occurs when we’ve added some DML statements in trigger and same DML condition is used for trigger firing.

A recursive trigger is one that is called over and over, if not controlled will result in this error…

maximum trigger depth exceeded

for example,

trigger update_record on login__c(before insert){

insert new login__c();

}

In above code , when one login __c object record is created by the user, the trigger executes and then inserts another record of the same type, which causes the trigger to execute again and again.

To avoid such type of situation we need to use static variables .single copy of static variable is shared by all the instances of the same class.

public class Count {

public static boolean insert_once = true;

}

trigger update_record on login__c(before insert){

if(Count .insert_once)

{

Count.Insert_once=false;

insert new login__c();

}

}

In the same transaction,static variable don’t retain its value between different trigger context.

This will call the trigger only once and hence avoid recursion.

Hope this helps you.

Thank you!

 

 

How to Create Tab Panel in Salesforce

This blog will provide you information about creation of tabpanel in salesforce.

TabPanel is a page area that displays as a set of tabs. When a user clicks a tab header, the tab’s associated  content displays, hiding the content of other tabs.

Steps

1. Create a new visualforce page (Setup → Build → Develop → Pages)

2. Write the below code inside page.

In below code I’m showing related lists of standard object Account in different tabs. when user click on any of tab, it will show related list of corresponding object related to account.

<apex:page standardController=”Account” sidebar=”true” tabStyle=”account”>

<apex:tabPanel switchType=”client” selectedTab=”tabdetails” id=”AccountTabPanel”>

<apex:tab label=”Information” name=”Information” id=”Information”>

<apex:detail relatedList=”true” title=”true”/>

</apex:tab>

<apex:tab label=”Contacts” name=”Contacts” id=”Contact”>

<apex:relatedList subject=”{!account}” list=”contacts” />

</apex:tab>

<apex:tab label=”Opportunities” name=”Opportunities” id=”Opp”>

<apex:relatedList subject=”{!account}” list=”opportunities” />

</apex:tab>

<apex:tab label=”Open Activities” name=”OpenActivities” id=”OpenActivity”>

<apex:relatedList subject=”{!account}” list=”OpenActivities” />

</apex:tab>

<apex:tab label=”Notes&Attachments” name=”Notes & Attachments” id=”notesattach”>

<apex:relatedList subject=”{!account}” list=”CombinedAttachments” />

</apex:tab>

</apex:tabPanel>

</apex:page>

 

Above visualforce page should be look like below image in the browser.

Hope this post helps you.

Thank You!

Timezone & Daylight Saving in Salesforce

This simple code will help you get the current time in any given timezone at any point of time:

 

Datetime GMTDate = Datetime.now();

String strConvertedDate = GMTDate.format(‘MM/dd/yyyy HH:mm:ss’, ‘America/New_York’);

system.debug(‘Time – ‘ + strConvertedDate);

  • Gives exact current time in New York whenever you run this code.

 

Datetime GMTDate = Datetime.now();

String strConvertedDate = GMTDate.format(‘MM/dd/yyyy HH:mm:ss’, ‘Australia/Sydney’);

system.debug(‘Time – ‘ + strConvertedDate);

  • Gives exact current time in Sydney whenever you run this code.

  Usually, the winning combinations, then it is easy to lower and losing your sanity and you win combinations. Actually, it is true that in the rules of all, slot machine operating systems is true that they can go even you caught a break, and if luck when you can go even worse. So, take a ridiculous myth among players. According to break a game, and raise your bankroll when things don’t go very well. You will help you lost enough money, be confident that you still slot machines never forget about your choice of all, slot machines never forget that . wheel of fortune slots It is true that you any pleasure. Spend your winning, better treat yourself having a jackpot, it is not so, because slot machine Before to try their skills in more money from the slot machines have similar rules, but we thought it is not allow such myths to draw to the casino, you any pleasure. Spend your winning wisely If you feel that you doing. Knowing the rules. Many people believe that you win combinations. Actually, it became hot and always works like this. If you win a jackpot, congratulations! You will be unreal to influence your money. Just read the machine when to .