function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Need Bulk trigger

trigger OppDescUpdate on Opportunity (before update) {
    if([0].stagename != trigger.old[0].stagename)
    {[0].description = 'opportunity stage changes from' + trigger.old[0].stagename + ' to '+[0].stagename;

Can u give a small idea to bulk this trigger. Just give steps to bulk this, no need code

Laxman RaoLaxman Rao

You have to loop over the, so that you logic works for all the records which are in trigger.


trigger OppDescUpdate on Opportunity (before update) {

   for(Opportunity  newOpp : {
      if(newOpp.stagename != trigger.old[0].stagename)
       newOpp.description = 'opportunity stage changes from' + trigger.old[0].stagename + ' to '+ newOpp.stagename;



here's a tes class that gets you to 100% for that trigger.  I'm sure someone can provide a better test than this hack job but the trigger looks good to me to handle bulk records so this will at least get you the test coverage


private class testOppTrigger{

static testMethod void testDescription() {

Profile pf = [Select Id from Profile where Name = 'Standard User'];

User u = new User();
u.FirstName = 'Test';
u.LastName = 'User';
u.Email = '';
u.CompanyName = '';
u.Title = 'Test User';
u.Username = '';
u.Alias = 'testuser';
u.CommunityNickname = 'Test User';
u.TimeZoneSidKey = 'America/Mexico_City';
u.LocaleSidKey = 'en_US';
u.EmailEncodingKey = 'ISO-8859-1';
u.ProfileId = pf.Id;
u.LanguageLocaleKey = 'en_US';
insert u;


Opportunity o = new Opportunity();
o.Name= 'test';
o.StageName= 'Prospecting';
o.CloseDate = System.Today();
insert o;

o.StageName = 'Qualified';
update o;