+ Start a Discussion
Janice HuJanice Hu 

I keep getting this error: "Type is not visible: Opportunity". How do I fix this?

I think it has to do with my Apex test classes - I tried to change some classes from "private" to "public" but the classes wouldn't save and just show this error instead. (I am going through Apex Academy on pluralsight, so this is the example from there - the suggested method was "private class" in line 2, but it still gives me the error when I try to save it as "public class".
private class LeadingCompetitorTest {
    @isTest static void createOppWithCompetitors() {
        // Create an opportunity and set required fields
        Opportunity opp = new Opportunity();
        opp.Name        = 'Big Deal';
        opp.CloseDate   = Date.today();
        opp.StageName   = 'Prospecting';

        // Set competitor price fields
        opp.Competitor_1_Price__c = 5000;
        opp.Competitor_2_Price__c = 15000;
        opp.Competitor_3_Price__c = 25000;

        // Set competitor fields
        opp.Competitor_1__c = 'Amazon';
        opp.Competitor_2__c = 'Google';
        opp.Competitor_3__c = 'Microsoft';

        insert opp;
        System.debug('Opportunity ' + opp.Name + ' inserted with all comeptitor fields populated.');

Amit Chaudhary 8Amit Chaudhary 8
I am able to save same code with public and private .

Please check you have created any class with Opportunity name ? If yes then please rename that class and try again.
Janice HuJanice Hu
Could you explain more what you mean by a class with Opportunity name? As in if a class has "Opportunity" in the file name, or something else?
Akshay Deshmukh1Akshay Deshmukh1
Amit may be correct. You should check if there are classes existing having name as 'Opportunity' or 'createOppWithCompetitors'.