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
RahulRahul 

Hello friends, Can you help me with The test class of this code.Thanks in advance

trigger updateborrowerinbucket1 on Account (after insert, after update) {

set<id> setid = new set<id>();
list<bucket1__C> bucketlist = new list<bucket1__C>();

for(Account a : trigger.new){
setid.add(a.Bucket_1__c);

}

for(bucket1__c bb : [select id,name,Borrower_Name__c,(select id, name, Mobile_Number__c from Accounts__r)from bucket1__C where id=:setid]){

bucket1__C bb2 = new bucket1__C();
bb2.id=bb.id;
bb2.count_of_patients__c=bb.Accounts__r.size();
bb2.Borrower_Name__c=bb.Accounts__r[0].Name;

bucketlist.add(bb2);

}

update bucketlist;
}
Best Answer chosen by Rahul
Yogeshwar TailorYogeshwar Tailor
Hi Sumit,

Please use the below code.
 
@isTest
public class Testupdateborrowerinbucket1 {

     static testMethod void positiveScenario(){
        
        bucket1__c bk = new bucket1__c();
        bk.name = 'test';
        insert bk;
        
        Account acc = new Account();
        acc.name='test1';
        acc.bucket1__c = bk.id;
        insert acc;
        
        bk.count_of_patients__c = 1;
        bk.Borrower_Name__c = acc.name;
        update bk;
        
        
        
        
    }
    
}

Thanks,
Yogesh

All Answers

Yogeshwar TailorYogeshwar Tailor
Hi Sumit,

Please use the below code.
 
@isTest
public class Testupdateborrowerinbucket1 {

     static testMethod void positiveScenario(){
        
        bucket1__c bk = new bucket1__c();
        bk.name = 'test';
        insert bk;
        
        Account acc = new Account();
        acc.name='test1';
        acc.bucket1__c = bk.id;
        insert acc;
        
        bk.count_of_patients__c = 1;
        bk.Borrower_Name__c = acc.name;
        update bk;
        
        
        
        
    }
    
}

Thanks,
Yogesh
This was selected as the best answer
RahulRahul
Thankyou Yogeshwar :)