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
sususudiosususudio 

Error in Test Method

Hi, I have written a web service method in an apex class, this works from vb.net but I cannot
create a test method for it, I get the error:
Error: Compile Error: Method does not exist or incorrect signature: UtilityCon.OpportunityInsert(Decimal, String, Date, String, String, String, String, String, Integer, String, Boolean, String, String, String, String, String, Decimal, Date, String) at line 13 column 13
Here is the test method:
@IsTest
public class TEST_UtilityCon {
static testMethod void myTest() {

String aaa;
aaa = UtilityCon.CR_ChangeEvent('a0D40000006FNt1EAG','a0C40000000HkqVEAS','old notes','mew notes');

String bbb;
bbb = UtilityCon.CR_ChangeClass ('a0D40000006FNt1EAG','a0C40000000HkqVEAS','old notes');

Date dt = date.parse('01/01/2011');
String opp;
opp = UtilityCon.OpportunityInsert (122.2, 'a0C40000002dO6hEAE', dt, '00330000004sgj0AAA', 'USD', 'Desc string sdfsf s', 'PipeLine', 'Professional 1', 2, '1967', false , 'Carl Anderson ', 'Notes come hrere', 'Class Interest', '00530000000dAAJAA2', 'Registered', 752.22, dt, 'Closed sale');
 }
}

This is the method:
WebService static String OpportunityInsert(Double ClassPrice , String ClassType, Date CloseDate,
String Contact, String CurrencyIsoCode, String Description,
String ForeCast, String GenericClassType,
Double InvoiceLine, String InvoiceNumber, boolean IsPrivate, String Name, String Notes,
String OpportunityType, String OwnerId, String RegistrationStatus, Double Paid, Date CRDateOfPayment,
String StageName
)

{

Opportunity o1 = new Opportunity();

o1.Class_Price__c = ClassPrice;
o1.Class_Type__c = ClassType;
o1.CloseDate = CloseDate;
o1.Contact__c = Contact;
o1.CurrencyIsoCode = CurrencyIsoCode ;

 

Any idea what's causing the error? Thanks!

 

Sue Davis

 

 

dmchengdmcheng

Did you define the WebService class as global?

sususudiosususudio

Yes:, global class UtilityCon {

 

Other test methods for this class are ok they are static too and return a string, its just this one I cant write the test method for

dmchengdmcheng

It might be more clear if you posted the complete class.  Also use the Code icon in the Post Message window to do monospace formatting.

sususudiosususudio

Here is the class:

 

global class UtilityCon {


WebService static Lead getLeadAddressByEmail(string LeadEmail)
{
Lead c = [SELECT Id, FirstName, LastName, Street, City, State, PostalCode from Lead WHERE Email = :LeadEmail];

return c;
}

WebService static String CR_ChangeEvent (string CRID, string EVENTID, String Notes2AddOldCR, String Notes2AddNewCR)
{
/* Class_Registration__c c = [SELECT Id, Registration_Status__c from Class_Registration__c WHERE id = :CRID]; */
Class_Registration__c c = Database.query(new selectall('Class_Registration__c').soql + ' where Id=\'' + CRID + '\'');
Class_Registration__c c2 = c.clone(false, true);
c2.Rescheduled_From__c = c.id;
c2.Class__c = EVENTID;

if(Notes2AddNewCR != '') {
if (c2.Registration_Notes__c == null) { c2.Registration_Notes__c = ' ';}
c2.Registration_Notes__c = Notes2AddNewCR + '; ' + c2.Registration_Notes__c;
}



Insert c2;
/* update old cr */
c.Registration_Status__c= 'Rescheduled';
c.Paid__c = 0;
c.Class_Price__c = 0;
c.Rescheduled_To__c = c2.Id;

if(Notes2AddOldCR != '') {
if (c.Registration_Notes__c == null) { c.Registration_Notes__c = ' ';}
c.Registration_Notes__c = Notes2AddOldCR + '; ' + c.Registration_Notes__c;
}

update c;

String Ret;
Ret = c2.Id;
return Ret;

}


WebService static String CR_ChangeClass (string CRID, string EVENTID, String Notes2Add)
{

Class_Registration__c c = Database.query(new selectall('Class_Registration__c').soql + ' where Id=\'' + CRID + '\'');
c.Class__c = EVENTID;

if(Notes2Add != '') {
if (c.Registration_Notes__c == null) { c.Registration_Notes__c = ' ';}
c.Registration_Notes__c = Notes2Add + '; ' + c.Registration_Notes__c;
}
update c;

String Ret;
Ret = c.Id;
return Ret;

}


WebService static User[] getUsers()
{
return [select Name, FirstName, Id from User];
}

WebService static Class_Registration__c[] getCRinfo()
{
return [SELECT id, Contact__r.FirstName from Class_Registration__c where Class__c= 'a0C40000002CZQvEAO'];
}


WebService static String OpportunityInsert (Double ClassPrice , String ClassType, Date CloseDate,
String Contact, String CurrencyIsoCode, String Description,
String ForeCast, String GenericClassType,
Double InvoiceLine, String InvoiceNumber, boolean IsPrivate, String Name, String Notes,
String OpportunityType, String OwnerId, String RegistrationStatus, Double Paid, Date CRDateOfPayment,
String StageName
)

{

Opportunity o1 = new Opportunity();

o1.Class_Price__c = ClassPrice;
o1.Class_Type__c = ClassType;
o1.CloseDate = CloseDate;
o1.Contact__c = Contact;
o1.CurrencyIsoCode = CurrencyIsoCode ;
o1.Description = Description;
o1.ForecastCategoryName = ForeCast;
o1.Generic_Class_Type__c = GenericClassType;
o1.Invoice_Line_Id__c = InvoiceLine;
o1.Invoice_Number__c = InvoiceNumber;
o1.IsPrivate = IsPrivate;
o1.Name = Name;
o1.Notes__c = Notes;
o1.Opportunity_Type__c = OpportunityType;
o1.OwnerId=OwnerId;
o1.Registration_Status__c = RegistrationStatus;
o1.Paid__c = Paid;
o1.CR_Date_of_Payment__c = CRDateOfPayment;
o1.StageName = StageName ;


Insert o1;
String Ret = o1.Id;
return Ret; }

}

 

here is the test  method class last line changed since it gives the error. Last line should be

 

opp = UtilityCon.OpportunityInsert (122.2, 'a0C40000002dO6hEAE', dt, '00330000004sgj0AAA', 'USD', 'Desc string sdfsf s', 'PipeLine', 'Professional 1', 2, '1967', false , 'Carl Anderson ', 'Notes come hrere', 'Class Interest', '00530000000dAAJAA2', 'Registered', 752.22, dt, 'Closed sale');

 

 

@IsTest
public class TEST_UtilityCon {
static testMethod void myTest() {

String aaa;
aaa = UtilityCon.CR_ChangeEvent('a0D40000006FNt1EAG','a0C40000000HkqVEAS','old notes','mew notes');

String bbb;
bbb = UtilityCon.CR_ChangeClass ('a0D40000006FNt1EAG','a0C40000000HkqVEAS','old notes');

Date dt = date.parse('01/01/2011');
String opp;
opp = UtilityCon.CR_ChangeClass ('a0D40000006FNt1EAG','a0C40000000HkqVEAS','old notes');
}
}