You need to sign in to do that
Don't have an account?
Francois Roux
Problem: I have written a trigger and a test. In the sandbox, the test saves and passes, but the trigger shows Code Coverage 0%. Can anybody help? Thanks in advance.
Custom object Fundraise__c has a lookup relationship to Account object and to Fund_c object. The trigger updates FundABC__c, FundDEF__c and Fund__GHI checkbox fields in Account object with 'true' everytime Fundraise__c gets created or updated with field Fund__c equal to FundABC, FundDEF or FundGHI respectively.
Trigger:
trigger updateAcct1 on Fundraise__c (after update) {
Set<Id> acid = new Set<Id>();
for(Fundraise__c temp0:Trigger.New) {
acid.add(temp0.Account__c);
}
Map<Id,Account> act = new Map<Id,Account>([Select Id from Account where Id in :acid]);
Set<Account> acts = new Set<Account>();
List<Account> acts1 = new List<Account>();
for(Fundraise__c temp:Trigger.New) {
if(temp.Fund__c == 'FundABC') {
if(act.containsKey(temp.Account__c)) {
Account upd = act.get(temp.Account__c);
upd.FundABC__c = true ;
acts.add(upd);
}
}
if(temp.Fund_Copy__c == 'FundDEF') {
if(act.containsKey(temp.Account__c)) {
Account upd = act.get(temp.Account__c);
upd.FundDEF__c = true ;
acts.add(upd);
}
}
if(temp.Fund_Copy__c == 'FundGHI') {
if(act.containsKey(temp.Account__c)) {
Account upd = act.get(temp.Account__c);
upd.FundGHI__c = true ;
acts.add(upd);
}
}
}
acts1.addAll(acts);
update acts1;
}
Test:
@isTest
public class testUpdateAcct1 {
static testmethod void invokeTrigger() {
Account ac = new Account();
ac.Name = 'Test Account';
Database.SaveResult sr = Database.insert(ac, false);
if(sr.isSuccess()) {
Fundraise__c p = new Fundraise__c();
p.Name = 'Essai';
p.Account__c = sr.getId();
Database.SaveResult sr1 = Database.insert(p, false);
if(sr1.isSuccess()) {
Id pid = sr1.getId();
Fundraise__c p1 = [Select Id, Name from Fundraise__c where Id =:pid];
p1.Fund_Copy__c = 'FundABC';
update p1;
p1.Fund_Copy__c = 'FundDEF';
update p1;
p1.Fund_Copy__c = 'FundGHI';
update p1;
p1.Fund__c = '';
update p1;
}
}
}
}
Trigger shows Code Coverage 0% after test in sandbox
Problem: I have written a trigger and a test. In the sandbox, the test saves and passes, but the trigger shows Code Coverage 0%. Can anybody help? Thanks in advance.
Custom object Fundraise__c has a lookup relationship to Account object and to Fund_c object. The trigger updates FundABC__c, FundDEF__c and Fund__GHI checkbox fields in Account object with 'true' everytime Fundraise__c gets created or updated with field Fund__c equal to FundABC, FundDEF or FundGHI respectively.
Trigger:
trigger updateAcct1 on Fundraise__c (after update) {
Set<Id> acid = new Set<Id>();
for(Fundraise__c temp0:Trigger.New) {
acid.add(temp0.Account__c);
}
Map<Id,Account> act = new Map<Id,Account>([Select Id from Account where Id in :acid]);
Set<Account> acts = new Set<Account>();
List<Account> acts1 = new List<Account>();
for(Fundraise__c temp:Trigger.New) {
if(temp.Fund__c == 'FundABC') {
if(act.containsKey(temp.Account__c)) {
Account upd = act.get(temp.Account__c);
upd.FundABC__c = true ;
acts.add(upd);
}
}
if(temp.Fund_Copy__c == 'FundDEF') {
if(act.containsKey(temp.Account__c)) {
Account upd = act.get(temp.Account__c);
upd.FundDEF__c = true ;
acts.add(upd);
}
}
if(temp.Fund_Copy__c == 'FundGHI') {
if(act.containsKey(temp.Account__c)) {
Account upd = act.get(temp.Account__c);
upd.FundGHI__c = true ;
acts.add(upd);
}
}
}
acts1.addAll(acts);
update acts1;
}
Test:
@isTest
public class testUpdateAcct1 {
static testmethod void invokeTrigger() {
Account ac = new Account();
ac.Name = 'Test Account';
Database.SaveResult sr = Database.insert(ac, false);
if(sr.isSuccess()) {
Fundraise__c p = new Fundraise__c();
p.Name = 'Essai';
p.Account__c = sr.getId();
Database.SaveResult sr1 = Database.insert(p, false);
if(sr1.isSuccess()) {
Id pid = sr1.getId();
Fundraise__c p1 = [Select Id, Name from Fundraise__c where Id =:pid];
p1.Fund_Copy__c = 'FundABC';
update p1;
p1.Fund_Copy__c = 'FundDEF';
update p1;
p1.Fund_Copy__c = 'FundGHI';
update p1;
p1.Fund__c = '';
update p1;
}
}
}
}
Are you facing the issue only in sandbox ?
Francois