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

Test class for mass upload of record in a custom object

Here i am trying to write a test class this class,which work is to upload large amount of records in a custom object.
Help me to write its test class please.

public class MassUpload{
    transient public Blob M_Body{get;set;}
    public String emailToalert{get;set;}
    public String retURL{get;set;}
    public MassUpload(){
    retURL = ApexPages.currentPage().getParameters().get('retURL');
    public void massUpload(){
        if(M_Body==null || M_Body.size()==0){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select a file to attach.'));
        List<String> csvFileLines=M_Body.toString().split('\n');
        if(csvFileLines!=null && csvFileLines.size()>0){
        MassUpload mass=new MassUpload(csvFileLines,emailToalert);
        }catch(Exception e){
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
krishna chaitanya 35krishna chaitanya 35
Hi llisa,

please try this code:
private class Test_MassUpload {

      static testMethod void testAttachments()
        Account acc=new Account(Name='Acme Inc');
        insert acc;
        Test_MassUpload controller=new Test_MassUpload(new ApexPages.StandardController(acc));
        controller.fileName='Unit Test Attachment';
        controller.fileBody=Blob.valueOf('Unit Test Attachment Body');
        List<Attachment> attachments=[select id, name from Attachment where];
        System.assertEquals(1, attachments.size());
Hi LLisa,
see the below links

Hello Krishna and kaek thanks for your reply.
it gives me an error like - "Constructor not defined: [MassUpload].&lt;Constructor&gt;(ApexPages.StandardController)"

To solve this issue i wrote the constructor like-

PageReference pageRef = Page.Mass_Upload;//VF page name
        pageRef.getParameters().put('id', String.valueOf(acc.Id)); //for page reference
        ApexPages.StandardController sc = new ApexPages.StandardController(acc);
        MassUpload controller = new MassUpload(sc);
      //  test_MassUploadExhibitA controller=new test_MassUploadExhibitA(new ApexPages.StandardController(acc));

But still it gives me the same error.