Activity Forums Salesforce® Discussions Test class of below Trigger in Salesforce?

  • Test class of below Trigger in Salesforce?

    Posted by Achintya on August 22, 2019 at 5:43 am
    Trigger AutoActivityCreation on Account(after update)
    {
        List<Task> task = new List<Task>();
        for (Integer i = 0; i < Trigger.new.size(); i++) {
            List<String> techs = Trigger.new[i].Toolsberry_new_tech_installs__c.split(‘;’);
            Integer added_tech = techs.size();
            if(Trigger.new[i].Toolsberry_new_tech_installs__c==’null’){
                added_tech=0;
            }
            List<String> re_techs = Trigger.new[i].Toolsberry_removed_tech_installs__c.split(‘;’);
            Integer removed_tech = re_techs.size();
            if(Trigger.new[i].Toolsberry_removed_tech_installs__c==’null’){
                removed_tech=0;
            }
            task.add(new Task( whatid=Trigger.new[i].Id, OwnerId=Trigger.new[i].OwnerId, Subject=’Technologies Added ‘+added_tech+’ , Removed ‘+removed_tech, Status = ‘Completed’, ActivityDate = system.today() ) ) ;
        }
        insert task;
    }
    • This discussion was modified 5 years, 2 months ago by  Forcetalks.
    • This discussion was modified 5 years, 2 months ago by  Forcetalks.
    • This discussion was modified 5 years, 2 months ago by  Achintya.
    Nikita replied 5 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Nikita

    Member
    August 22, 2019 at 5:52 am

    Hi Achintya,

    Please check this if it works for you.

    @isTest
    private class TriggerTestClass {

    static testMethod void autoTasktest() {
    // TO DO: implement unit test

    Account acc = new Account(
    Name = 'Test Account 1',
    Phone = '07123123123',
    Toolsberry_new_tech_installs__c = 'null',
    Toolsberry_removed_tech_installs__c = 'null');
    insert acc;

    acc.BillingCity = 'Test Area 2';
    update acc;

    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos