+ Start a Discussion
Prasanna1838Prasanna1838 

Constructor not defined: [ApexPages.StandardController].<Constructor>(Id)

Hi Everyone,
I am new to test classes.I tried all suggestions but stil it shows the same error.


public class fileAttachToMultipleRecordsController{ Public Attachment myfile; Public String VMfileName{get;set;} public String ContactIds{get;set;} public Contact con{get;set;} public List<Contact> contacts{get;set;} public fileAttachToMultipleRecordsController(){ contacts= new List<Contact>(); con= new Contact(); } Public Attachment getmyfile() { myfile = new Attachment(); return myfile; } public fileAttachToMultipleRecordsController(ApexPages.StandardController controller) { ContactIds= ApexPages.currentPage().getParameters().get('array'); } Public Pagereference Savedoc() { if(ContactIds!= null || ContactIds!= ''){ List<String> strConIds= ContactIds.split(','); for(Id conId:strConIds){ Attachment a = new Attachment(parentId =conId,name=myfile.name, body = myfile.body); insert a; VMfileName=a.Name; Task newTask = new Task(Description = 'Attached a file under the attachment sections',Priority = 'Normal',Subject ='Attached a File'+'-'+VMfileName,Status='Completed', ActivityDate=System.today(), whoid=conId); Insert newTask; } } PageReference pf=new PageReference('/003/o'); return pf; } @isTest(SeeAllData=true) public static void testfileAttachToMultipleRecordsController(){ String ContactIds; PageReference pr = Page.fileAttachToMultipleRecords; test.setCurrentPage(pr); fileAttachToMultipleRecordsController ftmr= new fileAttachToMultipleRecordsController(); ftmr.getmyfile(); ftmr.Savedoc(); Contact c=new Contact(); c.LastName='Test Name'; insert c; Contact c1=new Contact(); c1.LastName='Test Name1'; insert c1; ApexPages.StandardController controller = new ApexPages.StandardController(c.id); Attachment a = new Attachment(parentId =c.id,name='test Name'); insert a; String VMfileName='test name'; Task newTask = new Task(Description = 'Attached a file under the attachment sections',Priority = 'Normal',Subject ='Attached a File'+'-'+VMfileName,Status='Completed', ActivityDate=System.today()); Insert newTask; } }

 

yvk431yvk431

Think you need to modify your test method, the standard controller instantiation

 

ApexPages.StandardController controller = new ApexPages.StandardController(c.id);

 

It should be c instead of c.id

 

 

--yvk

 

Prasanna1838Prasanna1838

Thank you for your reply.The error is rectified,but my code coverage is still 58 and is unsuccessful.

The code isn't covered here. Its a list button where in ,when we choose multiple contacts and click on the button,the ids will be passed to the standard controller and will be seperated by (,).

Any ideas on how to implement this in test class

 

public fileAttachToMultipleRecordsController(ApexPages.StandardController controller) {
       ContactIds= ApexPages.currentPage().getParameters().get('array');
      }
 for(Id conId:strConIds){
                Attachment a = new Attachment(parentId =conId,name=myfile.name, body = myfile.body);
                insert a;