• CRM-plus
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hello,

 

I am trying to write the test class for my trigger. But I can't get further then 60%. 

Can someone help me with this?

 

trigger updateAcct onEvent (afterupdate) {

   

Set<Id> acctIds = new Set<Id>();    

for(Event e: [SELECT Subject,WhatId, Sales_Reps__c FROM EVENT WHERE ID IN:trigger.new]){

String wId = e.WhatId;

if(wId!=null && wId.startsWith('001') && !acctIds.contains(e.WhatId) && e.Sales_Reps__c == '1-5'){

acctIds.add(e.WhatId);   

}     

}

    for(Account a:[SELECT Sales_Reps__c FROM Account WHERE ID IN:acctIds]){

                 a.Sales_Reps__c = '1-5';

        update a;  

    }        

}    

 

Test class:

public class TestClass {

 

    static testMethod void myUnitTest() {

        //Create new Account

        Account acc = new Account(Name ='test');

            Set<Id> acctIds = new Set<Id>();

            insert acc;

 

        // Create new Event with fiction data

        Event c = new Event(WhatId=acc.ID, Subject='test',Sales_Reps__c='1-5',durationinminutes = 1440,isalldayevent = true,activitydate = System.today());

        Set<Id> ownerIds = new Set<Id>();

        String wId = c.WhatId;

            if(c.Update_Event__c ==true){

    acctIds.add(c.WhatId);

}

insert c;

        Test.startTest();

        try {

        Account a = [SELECT Name, Sales_Reps__c,Sales_LY__c, Description FROM Account WHERE ID =:acc.Id];

        a.Name='test';

        a.Sales_Reps__c ='1-5';

        a.Sales_LY__c = '1.750.000 - 2.000.000';

        a.Description='test';

        update a;

}

 

 catch (System.DmlException e) {

    System.debug('Event record could not be updated.');

    

    }

        Test.stopTest();   

    }

}

 

Looking forward to the answer!

 

Kind regards,

Hello,

 

I am trying to write the test class for my trigger. But I can't get further then 60%. 

Can someone help me with this?

 

trigger updateAcct onEvent (afterupdate) {

   

Set<Id> acctIds = new Set<Id>();    

for(Event e: [SELECT Subject,WhatId, Sales_Reps__c FROM EVENT WHERE ID IN:trigger.new]){

String wId = e.WhatId;

if(wId!=null && wId.startsWith('001') && !acctIds.contains(e.WhatId) && e.Sales_Reps__c == '1-5'){

acctIds.add(e.WhatId);   

}     

}

    for(Account a:[SELECT Sales_Reps__c FROM Account WHERE ID IN:acctIds]){

                 a.Sales_Reps__c = '1-5';

        update a;  

    }        

}    

 

Test class:

public class TestClass {

 

    static testMethod void myUnitTest() {

        //Create new Account

        Account acc = new Account(Name ='test');

            Set<Id> acctIds = new Set<Id>();

            insert acc;

 

        // Create new Event with fiction data

        Event c = new Event(WhatId=acc.ID, Subject='test',Sales_Reps__c='1-5',durationinminutes = 1440,isalldayevent = true,activitydate = System.today());

        Set<Id> ownerIds = new Set<Id>();

        String wId = c.WhatId;

            if(c.Update_Event__c ==true){

    acctIds.add(c.WhatId);

}

insert c;

        Test.startTest();

        try {

        Account a = [SELECT Name, Sales_Reps__c,Sales_LY__c, Description FROM Account WHERE ID =:acc.Id];

        a.Name='test';

        a.Sales_Reps__c ='1-5';

        a.Sales_LY__c = '1.750.000 - 2.000.000';

        a.Description='test';

        update a;

}

 

 catch (System.DmlException e) {

    System.debug('Event record could not be updated.');

    

    }

        Test.stopTest();   

    }

}

 

Looking forward to the answer!

 

Kind regards,