SFDC Developers

SFDC Developers Contact information, map and directions, contact form, opening hours, services, ratings, photos, videos and announcements from SFDC Developers, Internet Company, Hyderabad.

22/04/2013

When to use Before-Triggers
Before-trigger events occur before a record’s changes are committed to the database. This particular event is ideal for performing data validation, setting default values, or performing additional logic and/or calculations. Please keep in mind that in the case of before-insert events, because the event is executed before the record is committed to the database it will not have a record id.

Before-triggers in my opinion are the most efficient and are going to be your goto method for most of the triggers you will write for a couple of reasons. The first being that you can perform data validation and reject a record before it is committed to the database, meaning there is no cost to performance by the system having to roll back an update. Second, you can update fields or set default values for a record without having to initiate another DML command.

For example the code below illustrates setting a default value on a record. No DML required.
trigger setDefaultAccountValues on Account (before insert, before update) {
for (Account oAccount : trigger.new) {
oAccount.Industry = ‘Cloud Computing’;
}
}
When to use After-Triggers:
==================
After-trigger events occur after a record has been committed to the database, which means that records being inserted will have a record id available. This particular event is ideal for working with data that is external to the record itself such as referenced objects or creating records based on information from the triggered object.

For example the code below illustrates creating an Opportunity after an Account is created.
trigger createNewAccountOpportunity on Account (after insert) {
List listOpportunities = new List();

for (Account oAccount : trigger.new) {
Opportunity oOpportunity = new Opportunity();
oOpportunity.Name = oAccount.Name;
oOpportunity.AccountId = oAccount.Id;
oOpportunity.Stage = ‘Proposal’;
oOpportunity.CloseDate = System.today() + 30; //Closes 30 days from today

listOpportunities.add(oOpportunity);
}

if (listOpportunities.isEmpty() == false) {
Database.update(listOpportunities);
}
}

22/04/2013

Understanding a Trigger in Salesforce.com:
============================
What is a Trigger?
"A Trigger is a block of Apex Code that executes in response to a particular type of change in a record's data." from the Force.com Developer Guide Page 336

What does the above definition mean in simple English. Basically a trigger is an event that fires off when a record is changed.
by changed I mean, you can:
Update a Record - Updating an existing record.
Insert Record - Inserting a new record like a new Account or Contact.
Delete Record - before the record deletes make sure everything is valid.
These three Actions we call (Update, Insert, Delete) are the main functions of a trigger. Basically which one will use a trigger for.
Also one can use a trigger as a controller combine with Visualforce or calling a web service API.
People have asked the question "How can I override the Save button in Force.com" Plain and simple way is to write a trigger. Why or How?
Simple, when you create or update a record the only way your new information weather you added information to an existing record or changed it or you added a new record, one would have to click SAVE to place the information into the database.
By clicking Save if you have a trigger on that Object then you can fire it off, thus overriding the save button. It will save and do the commands you wrote in the trigger itself.

24/01/2012

what is cloudcomputing?

24/01/2012

feature of the cloud

24/01/2012

All salesforce informations in

Workbooks are sets of tutorials that introduce you to various features. They are a great way to get started with the platform. The Force.com Workbook introduces you to building applications on the platform.

23/01/2012
19/01/2012

“My Email to Salesforce”

Address

Hyderabad
500012

Website

Alerts

Be the first to know and let us send you an email when SFDC Developers posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Contact The Business

Send a message to SFDC Developers:

Share