You need to sign in to do that
Don't have an account?
Anil Kathari
need test class for this trigger
trigger ownerupdate on Account (before insert) {
set<id> setAccOwners= new set<id>();
for(Account acc: Trigger.new){
setAccOwners.add(acc.ownerID);
}
Map<id,user> user_map = new map<id,user>([select name from user where id in : setAccOwners]);
for (Account acc: Trigger.new){
user u = user_map.get(acc.ownerID);
acc.RecordOwner__c = u.name;
}
}
set<id> setAccOwners= new set<id>();
for(Account acc: Trigger.new){
setAccOwners.add(acc.ownerID);
}
Map<id,user> user_map = new map<id,user>([select name from user where id in : setAccOwners]);
for (Account acc: Trigger.new){
user u = user_map.get(acc.ownerID);
acc.RecordOwner__c = u.name;
}
}
When your are testing a trigger,
- you need to insert atleast 200+ records to test.
- Inside test Class you need to use Test.startTest() and Test.stopTest()
- Atleast ONE system.assert();
Please find the test class code,Although, I think your requirement can be solved using formula field to capture the Name of the Owner of an Account in a different field.
Thanks,
Prosenjit
You have to change in trigger.
1.) Write your line acc.RecordOwner__c = u.Id; instead of acc.RecordOwner__c = u.name; Because you can put user name in user look up field. You have to put Id in lookup fied
2.) After that, test class will run.
Test Class:
If you have any query, please let me know.
Thanks,
Arvind Kumar