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
sgsssgss 

Test Class for opportunity amount

write a soql query to display 100 opportunity record with amount greater than 10000 order by created date.Skip first 50 record and include record from recycle bin

//////Test class required for following code .Can anyone help in this considering all positive negative scenario


public class OpportunityClass {
    public static list<Opportunity> toQueryOnOpportunity(){
        list<Opportunity> listOpportunity = new List<Opportunity>([
                                                                    SELECT 
                                                                                            Id,
                                                                                                Name
                                                                    FROM 
                                                                                            Opportunity 
                                                                    WHERE 
                                                                                            amount>10000
                                                                    ORDER BY 
                                                                                            CreatedDate ASC
                                                                        LIMIT 
                                                                                            100 
                                                                    OFFSET 
                                                                                            12
                                                                        ALL ROWS
                                                                        ]
                                                                    );
        System.debug(listOpportunity);
        return listOpportunity;
    }    
}
Akshay_DhimanAkshay_Dhiman
Hi Supriya,

Try the below code.
//************************************   class   ********************************************​
public class OpportunityClass {
    public static list<Opportunity> toQueryOnOpportunity(){
        list<Opportunity> listOpportunity = new List<Opportunity>([
            SELECT 
            Id,
            Name
            FROM 
            Opportunity 
            WHERE 
            amount>10000
            ORDER BY 
            CreatedDate ASC
            LIMIT 
            100 
            OFFSET 
            12
            ALL ROWS
        ]);
                 System.debug(listOpportunity);
        return listOpportunity;
    }    
}
//************************************   class   ********************************************
@isTest
public class OpportunityClass_Test
{
    @isTest
    public static void toQueryOnOpportunity_Test()
    {
        List<Opportunity> oppList=new List<Opportunity>();
        Opportunity opp=new Opportunity();
        opp.name='my oppp';
        opp.StageName='Closed Won';
        opp.CloseDate=date.today().addDays(5);
        opp.Amount=10001;
        insert opp;
        Test.startTest();
      oppList=  OpportunityClass.toQueryOnOpportunity();
        Test.stopTest();
        System.assertNotEquals(1, oppList.size());
    }        
}



Thanks.
Akshay