You need to sign in to do that
Don't have an account?

Method does not exist or incorrect signature
I'm getting this error on line one 101.... co.CreateOppty()
I'm fairly new to APEX and I don't understand how to fix or where to begin with this. In the Sandbox all the code test perfectly but I can't get it to run in production (another issue I don't understand).
This is my test class:
@isTest private class clsOpptyTest { static testMethod void TestCode() { Date dTodayDate = date.today(); Date dNYCloseDate = date.newinstance(dTodayDate.Year()+1, 4, 1); Date dCYCloseDate = date.newinstance(dTodayDate.Year(), 4, 1); // Get an Admin User Id Id AdminId = [Select Id From User where firstname = 'Joe' and lastname ='Young'].Id; for (Profile Prof : [Select p.Name, (Select u.Id From Users u where u.IsActive = TRUE) From Profile p where p.Name = 'System Administrator']) { for (User users : Prof.users){ AdminId = users.Id; break; } } // Get the Account Agency RecordType ID Id strAgencyID = [Select Id From RecordType where sObjectType='Account' and Name='Agency' and isActive=true].Id; // Create test Accounts Account a0 = new Account(Name='Test0', Type='Prospective Agency', OwnerID=AdminId, RecordTypeId=strAgencyId, Prospect_Stage__c='BIF Signed', Sub_Type__c='General Agency', Total_Premium__c=4500000); Account a1 = new Account(Name='Test1', Type='Existing Agency', OwnerID=AdminId, RecordTypeId=strAgencyId, Prospect_Stage__c='Signed', Sub_Type__c='General Agency', Total_Premium__c=4000000); Account a2 = new Account(Name='Test2', Type='Existing Agency', OwnerID=AdminId, RecordTypeId=strAgencyId, Prospect_Stage__c='Signed', Sub_Type__c='General Agency', Total_Premium__c=3500000); Account a3 = new Account(Name='Test3', Type='Existing Agency', OwnerID=AdminId, RecordTypeId=strAgencyId, Prospect_Stage__c='Signed', Sub_Type__c='General Agency', Total_Premium__c=3000000); Account[] Acct = new Account[] {a0, a1, a2, a3}; insert Acct; // Create test Opportunities Opportunity o0 = new Opportunity(AccountID=a0.Id, OwnerId='00560000001VRy9', Name=a0.Name + ' - Test', StageName='Open', Type='Existing Business', Total_Premium__c=2000000, Committed_Premium__c=500000, CloseDate=dNYCloseDate); Opportunity o1 = new Opportunity(AccountID=a1.Id, OwnerId='00560000001VRy9', Name=a1.Name + ' - Test', StageName='Open', Type='Existing Business', Committed_Premium__c=1500000, Actual_Premium__c=0, Total_Premium__c=4500000, CloseDate=dNYCloseDate); Opportunity o2 = new Opportunity(AccountID=a2.Id, OwnerId='00560000001VRy9', Name=a2.Name + ' - Test', StageName='Open', Type='Existing Business', Committed_Premium__c=1500000, Actual_Premium__c=1550000, Total_Premium__c=4500000, CloseDate=dCYCloseDate); Opportunity o3 = new Opportunity(AccountID=a3.Id, OwnerId='00560000001VRy9', Name=a3.Name + ' - Test', StageName='Open', Type='Existing Business', Committed_Premium__c=1500000, Actual_Premium__c=1650000, Total_Premium__c=4500000, CloseDate=dCYCloseDate); Opportunity[] Oppty = new Opportunity[] {o0, o1, o2, o3}; insert Oppty; // Validate and Test trgOpptyAmt // The results of Amount = Amount should equal Total Premium if Actual Premium isn't greater than 0 Double AmtTest1 = [select Amount from Opportunity where id = :o0.Id].Amount; system.assertEquals(AmtTest1, 500000); Opportunity ou0 = new Opportunity(Id=o0.Id); ou0.Actual_Premium__c=800000; update ou0; Double AmtTest2 = [select Amount from Opportunity where id = :o0.Id].Amount; system.assertEquals(AmtTest2, 800000); Double AmtTest3 = [select Amount from Opportunity where id = :o1.Id].Amount; system.assertEquals(AmtTest3, 1500000); Opportunity ou1 = new Opportunity(Id=o1.Id); ou1.Committed_Premium__c=1800000; update ou1; Double AmtTest4 = [select Amount from Opportunity where id = :o1.Id].Amount; system.assertEquals(AmtTest4, 1800000); // Validate and Test clsCreateOppty clsCreateOppty CO = new clsCreateOppty(); CO.CreateOppty(); // Validate and Test clsCloseOppty String strType1 = [select Type from Account where id = :a2.Id].Type; system.assertEquals(strType1, 'Existing Agency'); Account au1 = new Account(Id=a2.Id); au1.Type='Terminated'; update au1; String strType2 = [select Type from Account where id = :a2.Id].Type; system.assertEquals(strType2, 'Terminated'); clsCloseOppty ClsO = new clsCloseOppty(); ClsO.CloseOppty(); String StageTest1 = [select StageName from Opportunity where id = :o2.Id].StageName; system.assertEquals(StageTest1, 'Closed/Lost'); String StageTest2 = [select StageName from Opportunity where id = :o3.Id].StageName; system.assertEquals(StageTest2, 'Closed/Won'); } }
This is the clsCreateOppty that has the method it's not finding;
public class clsCreateOppty { public void CreateOppty(){ List<Opportunity> OpptyToCreate = new List<Opportunity>(); // Set This Years Close date to use in the record query Date dQueryDate = date.newinstance(date.today().year(),04,01); // Set Close date to April 1 of next year Date dCloseDate = date.newinstance(date.today().year()+1,04,01); // Get the string value of the Close date year String strCloseDate = string.valueOf(dCloseDate); String[] StringDate = strCloseDate.split('-'); String strCloseYear = StringDate[0]; system.debug(strCloseYear); for (Account A : [Select a.Id, a.Name, a.OwnerId, a.Total_Premium__c, (Select o.CreatedDate, o.Committed_Premium__c From Opportunities o where o.CloseDate = :dQueryDate order by o.CreatedDate desc) From Account a where a.type in ('Prospective Agency', 'Existing Agency')]) { // Set default value for Committed Premium double CP = 0; // Use the most current opportunity which there should only be one but just in case break out of the loop after the first pass for (Opportunity opp : a.opportunities){ CP = opp.Committed_Premium__c; break; } Opportunity O = New Opportunity(Accountid=a.Id, CloseDate=dCloseDate, Name=a.Name + ' - ' + strCloseYear, OwnerId='00560000001VRy9', StageName='Open', Type='Existing Business', Committed_Premium__c=CP, Last_Year_s_Commitment__c=CP, Total_Premium__c=a.Total_Premium__c); OpptyToCreate.add(O); } insert OpptyToCreate; } }
It seems that you did not create a constructor . Create a default constructor in class so that you can easily call constructor in test method : Public clsCreateOppty(){}
Hope this helps.