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
Filipe BaradelliFilipe Baradelli 

The code stops working

I use a code that initially works, but after some tests it stops working. I copy all the code when it works and after that it stops, I paste it, but doesn't works.
This is the part of the code (that belongs to class Catalog Controller from Catalog Order package):
public PageReference toCatalog() {
   
 // begins here    

        Product2 p2 = new Product2();
        p2.Name = 'P2';
        p2.isActive = true;
        insert p2;
        
        Opportunity opp2 = new Opportunity();
        opp2.Name = 'OPP TESTE';
        opp2.CloseDate = System.Today();
        opp2.StageName = 'Prospecting';
        insert opp2;

//ends here

        if(!Product2.sObjectType.getDescribe().isAccessible()) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'Insufficient access'));
            return null;
        }
        PageReference next = new PageReference('/apex/catalog_products');
        next.setRedirect(false);
       
        // Directing to Catalog
        return next;
        }

 
EnreecoEnreeco
Which error do you see?