You need to sign in to do that
Don't have an account?
Filipe Baradelli
Can someone help me?
Illegal assignment from List<Product2> to Pricebook2
Product2 p2 = new Product2(); p2.Name = 'P3'; p2.isActive = true; insert p2; Pricebook2 meupricebook = new Pricebook2(); meupricebook.Name = 'Meu Pricebook'; meupricebook.isActive = true; insert meupricebook; PriceBook2 meupricebookrec = [SELECT Id FROM Product2 WHERE id =: meupricebook.Id]; Id stdpricebookrecid = Test.getStandatPricebookId(); PriceBookEntry sdtpricebookentry = new PriceBookEntry(); sdtpricebookentry.Product2Id = p2.Id; sdtpricebookentry.Pricebook2Id = stdpricebookrecid; sdtpricebookentry.UnitPrice = 2000; sdtpricebookentry.isActive = true; insert sdtpricebookentry; PriceBookEntry meupricebookentry = new PriceBookEntry(); meupricebookentry.Product2Id = p2.Id; meupricebookentry.Pricebook2Id = meupricebookrec.Id; meupricebookentry.UnitPrice = 5000; meupricebookentry.isActive = true; insert meupricebookentry; Opportunity opp2 = new Opportunity(); opp2.Name = 'OPP TESTE 2'; opp2.CloseDate = System.Today(); opp2.StageName = 'Prospecting'; insert opp2; OpportunityLineItem meuopplineitem = new OpportunityLineItem(); meuopplineitem.OpportunityId= opp2.Id; meuopplineitem.PricebookEntryId = meupricebookentry.Id; meuopplineitem.UnityPrice = 7000; meuopplineitem.Quantity = 5; insert meuopplineitem;
Can someone help me?
If that's true then i will assume that the SOQL query fetches only one record (by looking at your code).
replace code at line 23 with following code: let me know, if its sorted.
Select it as Best Answer, if it solves your problem.
you are trying to fetch records from Product2 in PreiceBook2 variable.
To fetch record from Product2 use:
To fetch record from PriceBook2 use: Handle variable names accordnigly.
Undo the changes i suggested earlier.
Select it as Best Answer, if it solves your problem.
There is no error, but when I execute it, nothing about the code is done.
as rightly pointed out by @Lalitha, it seems this code is from a Test class, and if that's true, any DML operation will have no effect on your Org Data.
It's from Catalog Order package's Class (Catalog Controller). I'm trying to create an Opportunity when the catalog order is submited and that contains the products that are in the final catalog order. I've tried by the process builder, but I could not add the products. Sorry by the noob mistakes, I'm trying to learn it.
This method is used in Test Class.
Retreive the id for any existing record using SOQL query.
Like:
If you are trying to access id of recently inserted record, reference it like:
Hope it helps.
I'm not being able to do the condition. My problem is that the variables that have what I need are not accessible on " toCatalog() " and I can't put these codes (a part more simple that works, like to create an Opportunity and a product) in other places.