Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
@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
2 answers
  1. Jan 22, 2019, 3:56 AM
    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.
Loading
0/9000