You need to sign in to do that
Don't have an account?
priyankasingla3101.3916265522429534E12
Any help will be appreciated.
Unable to create a PricebookEntry using apex code
Hi,
I am trying to create a PricebookEntry in my apex code, but it is giving me the following error:
Error: Compile Error: Invalid constructor syntax, name=value pairs can only be used for SObjects
Here is my code:
1.Pricebook2 pb = [select Id, IsActive from PriceBook2 where IsStandard=True]; 2. Product2 p1 = new Product2(Name='Prod 1', Family='Container', Description='Prod 1 Description'); 3. insert p1; // Create a pricebook entry 4. PricebookEntry pbe = new PricebookEntry (Pricebook2Id=pb.id, Product2Id=p1.id, IsActive=true, UnitPrice=100.0); 5. insert pbe;I am getting this error at Line 4. PricebookEntry is a standard object in Salesforce, but I am not able to understand why I am getting this error.
Any help will be appreciated.
I copied the same code that you provided and it allowed me to save it.
Could you put all the code that you currently have?
Thanks!
My class name was PriceBookEntry itself, thats why it was not considering it as an sObject. :) Now I changed my class name to PriceBookEntryTest, and it is working fine. Thanks anyways.. :)
"For creating PriceBookEntry you can use this code."
If you find your Solution then mark this as the best answer.
Thank you!
Regards
Suraj Tripathi