• #19058
    Salesforce | Manpreet Manpreet #229
    Forcetalks

    Adding Products to Opportunity Line items in salesforce?

    I need to Add Products to Opportunity Line items.How can i achieve it?

     

    #19305
    Salesforce | Suraj Suraj #168
    Forcetalks

    Hi Manpreet,

    Try this,

    public class ProductEntry {
    public static void CustomProductadd(){
    Product2 pro=new Product2(name =’ProductName’,IsActive=true);
    insert pro;
    PriceBook2 customprice=new PriceBook2(name=’CustomPriceBook’,IsActive=true);
    insert customprice;
    PriceBook2 standardPb=[select id from Pricebook2 where isStandard=true];
    PriceBookEntry pbeStandard=new PriceBookEntry(Product2Id=pro.Id,PriceBook2Id=standardPb.Id,isActive=true,UnitPrice=1);
    insert pbeStandard;
    PricebookEntry pbe=new PriceBookEntry(Product2Id=pro.Id,PriceBook2Id=customprice.Id,isActive=true,UnitPrice=1);
    insert pbe;
    OpportunityLineItem lineitem=new OpportunityLineItem(OpportunityId=’OPPID’,PriceBookEntryId=pbe.Id,Quantity=1,Unitprice=1);
    insert lineitem;
    }
    }

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?