When a new Account record is inserted verify the industry field value, if the industry field value is Education then assign the owner as karthik.

1.6K    Asked by AvaBlack in Salesforce , Asked on Mar 2, 2020
Answered by Ava Black

trigger account owner on Account (before insert) {

User u=[select id from User where username=’developer@batch0267.com’];

for(Account a:Trigger.New){

if(a.Industry==’Education’){

a.ownerId=u.id;

}

}

}

TestClass :

@isTest

private class AccountOwnerTest {

@isTest

static void testme(){

User u=[select id from User where username=’developer@batch0267.com’];

Integer count=[select count() from Account];

Account a=new Account(Name=’Test’,Industry=’Education’);

try{

insert a;

}catch(Exception e){

System.debug(e);

}

Integer size=[select count() from Account];

System.assertEquals(size,count+1);

Account acc=[select id ,ownerId from Account where id=:a.id];

System.assertEquals(acc.ownerId,u.id);

}

}



Your Answer

Interviews

Parent Categories