0

I have a Quote trigger for which I am trying to write tests.

Here is my test class. However, I am getting some wierd errors while writing this.

@isTest
public class TriggerQuoteTest {

    @testSetup
    static void createData() {

        Quote quote = new Quote();

        quote.OpportunityId = '--test-opportunity-id-here';

        INSERT quotes;
    }

    public static testMethod void TestDisplayQuote1() {
    }
}

Can somebody suggest and help?

  1. The above version gives me error as below:

Error: Compile Error: Variable does not exist: Opportunity at line 9 column 15

I tried with all combinations of uppercase, mixed case and camel case and the ones matching with API names(OpportunityId, opportunityid, Opportunityid, opportunityId), but this error just seem to stick.

  1. Since, I was getting this, I use this version of creating the Quote - new Quote(field1=value1, ...). So, I updated my trigger to below.

    @isTest
    public class TriggerQuoteTest {
    
        @testSetup
        static void createData() {
    
            Quote quote = new Quote(OpportunityId='--test-opportunity-id-here');
            INSERT quotes;
        }
    
        public static testMethod void TestDisplayQuote1() {
        }
    }
    

But, now Salesforce is giving me another exception as below.

Error: Compile Error: Invalid constructor syntax, name=value pairs can only be used for SObjects: Quote at line 7 column 27

Can somebody put some light here as to why I cannot create Quote object for my test?

0

If the code posted above is what you have currently, then you seem to have a typo in your insert statement.

You are trying to create the Quote instance as:

Quote quote = new Quote();

And that you are trying to insert using an extra "s" in the name:

insert quotes; // notice extra s here

Removing the extra "s" here should fix the problem.

insert quote;
0

Usually this issue occurs when your organization has a class with the same name as the standard platform class. In your case Quote i.e. Your organization might be having a class named as Quote.

Navigate to Setup > Apex Classes > and search for a class which is named as Quote and rename it to something else.

You are getting the above errors due to following reasons

  • In your first attempt, compiler searches for the OpportunityId property in your custom made class which it can't find and hence gives you compilation error.
  • In your second attempt, compiler searches for the Constructor with parameters in your custom made class which it can't find and hence gives you compilation error.

You should never create classes with the names which are already being used by the platform.

Once you rename your custom made Quote class to something else, make sure to compile all your classes by navigating to Setup > Develop > Apex Classes > Click on Compile all classes and then try saving your above class.

Also, one more compilation issue which you need to correct is, you are using uninitialized variable quotes to perform DML which again will give you compilation error. You should use quote i.e. the variable which you initialized as an instance of Quote to perform DML i.e replace insert quotes to insert quote. Once you compile all your classes and fix the above issue, your class should be saved successfully.

Note : Apex is case insensitive, so you don't have to worry about case while writing code in apex.

1
  • Hi @Samridhi if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. Apr 18 '19 at 6:06

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.