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
farah sheriffarah sherif 

guys im getting an error on the below test class can anyone help please

@isTest
public class AssetTriggerTest2 {

    @isTest static void test(){
        
        Account acc = new Account();
        acc.Name = 'farah test';
        insert acc;
        
        Opportunity opp = new Opportunity();
        opp.Name = 'tests';
        opp.CloseDate = Date.today();
        opp.StageName ='Demo';
        opp.AccountId = acc.Id;
        opp.Type='New';
        opp.Demo_Date__c = Date.today();
        opp.New_Vehicle_Feed_Provider__c ='AutoFunds';
        insert opp;
        
        Product2 p1 = new Product2();
        p1.Family = '360 Suite';
        p1.IsActive = true;
        p1.Name ='360 Suite';    
        insert p1;
        
        Id pricebookId = Test.getStandardPricebookId();
        PricebookEntry pb1 = new PricebookEntry();
        pb1.Product2Id =p1.Id;
        pb1.Pricebook2Id = pricebookId;
        pb1.UnitPrice = 100.00;
        pb1.IsActive = true;
        insert pb1;
        
        
        OpportunityLineItem oli = new OpportunityLineItem(
                                                 OpportunityId = opp.Id,
                                                 Quantity = 5,
                                                 PricebookEntryId = pb1.Id,
                                                 TotalPrice = Quantity * pb1.UnitPrice
                                                                                    );
        insert oli;
        

        opp.StageName = 'Closed Won';
        update opp;
        
       
        
    }
    
}




error
Variable does not exist: Quantity


although it does exist and when i added a value to it it worked fine
Best Answer chosen by farah sherif
Le NguyenLe Nguyen
The problem is Quantity in your codes has not been declared anywhere, so TotalPrice = Quantity *pb1.UnitPrice will be invalided.

Also, TotalPrice of OpportunityLineItem will be calculated automatically based on unitPrice and Quantity. I think you just delete TotalPrice=Quantity*pb1.UnitPrice.

All Answers

Le NguyenLe Nguyen
The problem is Quantity in your codes has not been declared anywhere, so TotalPrice = Quantity *pb1.UnitPrice will be invalided.

Also, TotalPrice of OpportunityLineItem will be calculated automatically based on unitPrice and Quantity. I think you just delete TotalPrice=Quantity*pb1.UnitPrice.
This was selected as the best answer
farah sheriffarah sherif
thank u , can u give me your email for further questions?