+ Start a Discussion
dhruv aroradhruv arora 

please help me in writting test class for this triggre.

trigger owner on Account (before update) {
user u =[select id,firstname from user where firstname='dhruv' limit 1];
list<Account> a = new list<Account>();
for (account acc:trigger.new)
{
    acc.name=u.firstname;
    //a.add(acc);
}
   //update a;   
}
Best Answer chosen by dhruv arora
sfdcMonkey.comsfdcMonkey.com
hi dhruv
try this class
@isTest 
private class HelloWorldTestClass {
   
  
    static testMethod void insertNewUser() {
        Profile pAdmin = [SELECT Id FROM Profile WHERE Name='System Administrator'];
         User testUser = new User();
                                       testUser.firstName = 'dhruv';
                                       testUser.LastName = 'user';
                                       testUser.Alias = 'lias';
                                       testUser.profileId = pAdmin.id ;
                                       testUser.Email = 'testClassuser3@user.com';
                                       testUser.UserName= 'john@3698596985acme.com';
                                       testUser.CommunityNickname = 'testClassuser3@salesforce.com';
                                       testUser.EmailEncodingKey ='ISO-8859-1';
                                       testUser.LanguageLocaleKey = 'en_US';
                                       testUser.TimeZoneSidKey ='America/Los_Angeles';
                                       testUser.LocaleSidKey = 'en_US';
                                       testUser.Country = 'United States';
                                       testUser.IsActive = true;
        insert testUser;
        
      Account acc = new account();
        acc.Name = 'dhruv1';
        insert acc;
        acc.Name = 'dhruv';
        update acc;
        
    
}
    }
Thanks
let me inform if it helps you and mark it best answer so it make proper solution for others :)
 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi dhruv
try this class
@isTest 
private class HelloWorldTestClass {
   
  
    static testMethod void insertNewUser() {
        Profile pAdmin = [SELECT Id FROM Profile WHERE Name='System Administrator'];
         User testUser = new User();
                                       testUser.firstName = 'dhruv';
                                       testUser.LastName = 'user';
                                       testUser.Alias = 'lias';
                                       testUser.profileId = pAdmin.id ;
                                       testUser.Email = 'testClassuser3@user.com';
                                       testUser.UserName= 'john@3698596985acme.com';
                                       testUser.CommunityNickname = 'testClassuser3@salesforce.com';
                                       testUser.EmailEncodingKey ='ISO-8859-1';
                                       testUser.LanguageLocaleKey = 'en_US';
                                       testUser.TimeZoneSidKey ='America/Los_Angeles';
                                       testUser.LocaleSidKey = 'en_US';
                                       testUser.Country = 'United States';
                                       testUser.IsActive = true;
        insert testUser;
        
      Account acc = new account();
        acc.Name = 'dhruv1';
        insert acc;
        acc.Name = 'dhruv';
        update acc;
        
    
}
    }
Thanks
let me inform if it helps you and mark it best answer so it make proper solution for others :)
 
This was selected as the best answer
dhruv aroradhruv arora
Thanks piyush.It helped.