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
Saumya SumanSaumya Suman 

There is opportunity and opportunity lineitem. Which collection we used here?

Raj VakatiRaj Vakati
Its an List .. 

only Opportunity can have more than  opportunity lineitem 

 
​Account objAccount = new Account();
objAccount.Name = 'Test';
Insert objAccount;

Opportunity objOpporunity = new Opportunity();
objOpporunity.Name = 'Test Opporutnity';
objOpporunity.AccountId = objAccount.Id;
objOpporunity.StageName = 'Closed Won';
objOpporunity.CloseDate = system.Today();
Insert objOpporunity;

Product2 objProduct = new Product2();
objProduct.Name = 'Test';
objProduct.Description = 'Test';
objProduct.RevRec_StartDate__c = system.today();
objProduct.RevRec_EndDate__c = system.today().addDays(1);
Insert objProduct;

PriceBook2 pb2Standard = [select Id from Pricebook2 where isStandard=true];
PricebookEntry objPBEntry = new PricebookEntry(Pricebook2Id = pb2Standard.Id, Product2Id=objProduct.Id,UnitPrice=500,IsActive=true);
Insert objPBEntry;

OpportunityLineItem objLineItem = new OpportunityLineItem();
objLineItem.PriceBookEntryId = objPBEntry.Id;
objLineItem.OpportunityId = objOpporunity.Id;
objLineItem.Quantity = 1;
objLineItem.Unitprice = 500;
Insert objLineItem;

OpportunityLineItem objLineItem = new OpportunityLineItem(); 
objLineItem.PriceBookEntryId = objPBEntry.Id;
 objLineItem.OpportunityId = objOpporunity.Id;
 objLineItem.Quantity = 1; 
objLineItem.Unitprice = 500;
 Insert objLineItem;


 
Saumya SumanSaumya Suman
I am not getting it where we use list here?