1

I have a custom controller on a custom object and I am trying to write a test class. However, when I try to save the test class, I get the error:

Compile Error: Method does not exist or incorrect signature: [Deal_Summary__c].add(Deal_Summary__c) at line 39 column 9

Does anyone know how I can fix this?

Controller:

public class DSReviewController {
    public Deal_Summary__c myDS;
    public DSReviewController(ApexPages.StandardController stdController){
        this.myDS = (Deal_Summary__c)stdController.getRecord();
    }
    public void review() {
        myDS.Manager_Review__c = TRUE; 
        update myDS;
    }
}

Test Class:

@Istest
private class TestDealSummController2
{
    static testMethod void testMyController1()
    {    
        Account acct1 = TestCreateRecords.createAcct(0);
        insert acct1;

        Opportunity opp1 = TestCreateRecords.createOppNew(acct1.Id);
        insert opp1;

        Deal_Summary__c DS1 = new Deal_Summary__c();
            DS1.Opportunity__c = opp1.Id;
            DS1.Publisher_s_Legal_Name__c = opp1.AccountId;
            DS1.Agreement_Effective_Date__c = date.newinstance(2025,1,31);
            DS1.Net_Payment_Term_Days__c = 60;

        ApexPages.StandardController DealSumm1 = new ApexPages.standardController(opp1);
        DSReviewController DealSummCont1 = new DSReviewController(DealSumm1);
        DealSummCont1.myDS.add(DS1);
        DealSummCont1.save();
    }
}
2

SObject does not have an add method. The error message is pretty self descriptive. It looks like you are trying to perform an assignment, which should look like:

DealSummCont1.myDS = DS1;

instead of:

DealSummCont1.myDS.add(DS1);

You also need to pass a Deal_Summary__c standard controller to your extension:

ApexPages.StandardController controller = new ApexPages.standardController(DS1);

instead of:

ApexPages.StandardController DealSumm1 = new ApexPages.standardController(opp1);
| improve this answer | |
  • Thanks Adrian. I did notice that after I posted. I changed the line and it saves, but now the error below is thrown when I run the test: 'System.TypeException: Invalid conversion from runtime type Opportunity to Deal_Summary__c Class.DSReviewController.<init>: line 6, column 1 Class.TestDealSummController2.testMyController1: line 38, column 1' Any ideas? – J. Neilan Oct 9 '15 at 19:24
  • Sorry, line 38 should actually be line 19. I typed incorrectly. – J. Neilan Oct 9 '15 at 19:36
  • So I changed "opp1" in line 18 to "DS1" and now I get: 'System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Class.DSReviewController.review: line 8, column 1 Class.TestDealSummController2.testMyController1: line 21, column 1' – J. Neilan Oct 9 '15 at 20:01
  • 2
    @J.Neilan These error messages are all very self descriptive. You cannot update a record that has never been inserted. Pretty straightforward. Just insert your Deal_Summary__c. – Adrian Larson Oct 9 '15 at 20:02
  • Thanks so much! I'm new to testing for controllers so the error message are a bit cryptic for me yet. Thanks for your help, it worked! – J. Neilan Oct 9 '15 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.