function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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.