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
Amrita Priyadarshini PandaAmrita Priyadarshini Panda 

what will be the test class for bellow apex class?

apex coding
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi  Amrita,

May I suggest you to please check the Test generator App From app Exchange. Please check the below link to Best Practice in Test classes. Hope it helps.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
YogeshMoreYogeshMore
Hi Amrita,

You can try following test class.
 
@isTest
public class AttachmentRestriction_Test{
    
    // Test Method to cover try block
    public static testMethod void TestMethod1(){        
        
        // Created account record for parent id to attachment 
        Account acc = new Account();
        acc.Name = 'TestAcc';
        insert acc;
        
		Attachment att = new Attachment();
		att.Name = "TestAtt.txt";
		att.Body = "test body";
		att.parentId = acc.Id;
		insert att;
		
        // created object of the class
        AttachmentRestriction testObj = new AttachmentRestriction();
        testObj.attRestriction(att);
    }
    
    // this methos to throw error and cover catch block
    public static testMethod void TestMethod2(){        
        AttachmentUploadController testObj = new AttachmentUploadController();
		Attachment att = new Attachment();
        testObj.attRestriction(att);
    }
}

Please mark this answer as SOLVED and BEST ANSWER if it helps you.

Regards,
Yogesh More
Salesforce consultant || Salesforce Developer
more.yogesh422@gmail.com || yogeshsfdc11@gmail.com
www.yogeshmore.com || Skype:-yogesh.more44