You need to sign in to do that
Don't have an account?
SFDC_Learner
Need Bulk trigger
trigger OppDescUpdate on Opportunity (before update) { Can u give a small idea to bulk this trigger. Just give steps to bulk this, no need code |
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;
}
}
}
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;
}
}
}