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
SFDC_LearnerSFDC_Learner 

Need Bulk trigger

trigger OppDescUpdate on Opportunity (before update) {
    if(trigger.new[0].stagename != trigger.old[0].stagename)
    {
        trigger.new[0].description = 'opportunity stage changes from' + trigger.old[0].stagename + ' to '+ trigger.new[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 trigger.new, so that you logic works for all the records which are in trigger.

 

trigger OppDescUpdate on Opportunity (before update) {

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

    }
}

SFAdmin5SFAdmin5

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

 

@isTest
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 = 'testuser@test123456789.com';
u.CompanyName = 'test.com';
u.Title = 'Test User';
u.Username = 'testuser@test123456789.com';
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;

system.runAs(u){

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

o.StageName = 'Qualified';
update o;


}

}

}