When ever new Account is inserted with Industry as ‘Banking ‘ then set the phone as ‘999’

By | November 16, 2019

Hi, Here we have written trigger for Account object. Whenever new Account is inserted with Industry as ‘Banking’ then set the phone as ‘999’. For this trigger we written Test class…

Trigger

trigger phoneUpdate on Account (before insert) {
    for(Account a: Trigger.New){
        if(a.industry=='Banking'){
            a.phone='999';
        }
    }
}

Test Class for the Trigger.

@isTest
private class PhoneTest {
    testmethod static void testme(){
        Account acc=new Account();
        acc.Name='SalesforceCodes';
        acc.Industry='Banking';
        try{
        	insert acc;
        }catch(Exception e){
            
        }
        Account a=[select id,phone from Account where id=:acc.Id];
        System.assertEquals(a.phone,'999');
    }
}
Share this...
Share on Facebook
Facebook
Email this to someone
email

Leave a Reply

Your email address will not be published. Required fields are marked *