0

I have a requirement to cover the quote and quote line item creation from one form in a visualforce.

In the image below you can see the visualforce design:

Visualforce to create quote and quote line item

The product information that will be traslated to the quote line item is processes by a wrapper class.

I am not able to receive both sections of the page (quote fields data in the first section and product information in the second one) in the controller. If I receive the product information, all the quote fields are populated as null.

Could you please help me? for more information click here

0

You can try the code below to add Quote along with Line Item in the same VF Page:-

Controller:-

 public class OppPageCloneController {
    public boolean show{get;set;}
    public id pdtId{get;set;}
    public Quote op{get;set;}
    public QuoteLineItem oli{get;set;}
    public string pb{get;set;}
    public Id opid{get;set;}
    public id prodid{get;set;}
    public list<QuoteLineItem> OliList{get;set;}
    public list<Quotelineitem> OliCreate;
    public integer deleteIndex{get;set;}

    public OppPageCloneController()
    {
        show=false;
        oli=new QuoteLineItem();
        op=new Quote();
        OliList=new list<QuoteLineItem>();
        OliCreate=new list<Quotelineitem>();
    }

    public void save(){
                pricebook2 spbid=[select id from pricebook2 where isStandard=true limit 1];

        opportunity o1=[select id from opportunity limit 1];
        op.OpportunityId=o1.id;
        op.Pricebook2Id=spbid.id;
        upsert op;
        map<id,id>pdtTopbemap=new map<id,id>();

        for(pricebookentry pb:[select product2id,id from pricebookentry where pricebook2id =:spbid.id ])
        {
            pdtTopbemap.put(pb.product2id,pb.id);
        }
        for(QuoteLineItem o:OliList)
        {
            o.QuoteId=op.id;
            o.unitprice=o.unitprice; 
            o.quantity=o.quantity;
            o.pricebookentryid=pdtTopbemap.get(o.product2id);
            o.Product2Id=o.product2id;
            OliCreate.add(o);
        }
        insert OliCreate;
    }
    public void AddOli()
    {
     show=true;
     QuoteLineItem olitemp = new QuoteLineItem();
     OliList.add(olitemp);
    }

 public void deleteOpp()
{
 OliList.remove(deleteIndex);
}
}

Page:-

 <apex:page Controller="OppPageCloneController" standardStylesheets="true"  >
<apex:detail relatedList="true"/>
    <apex:form >

    <apex:pageBlock title="Opportunity Page">
        <apex:pageBlockSection > 
        <apex:inputField value="{! Op.Name }"/>

      <apex:commandButton action="{!save}" value="save"/>
 <apex:param name="opid" value="{!op.id}" assignTo="{!opid}"/>
            <apex:outputText value="{!op.id}"></apex:outputText>
        </apex:pageBlockSection>
<apex:pageBlockSection >
        <apex:commandButton action="{!AddOli}" value="Add List"  reRender="a"/>
        </apex:pageBlockSection>          
          <apex:pageBlockSection id="a" title="Line Items" > 
              <apex:variable var="index" value="{!0}" />
               <apex:repeat value="{!OliList}" var="ol">
            <apex:inputField value="{!ol.Quantity}"/>   
            <apex:inputField value="{!ol.UnitPrice}"/>
                  <apex:inputField value="{!ol.product2id}"/><br/>
              <apex:commandButton id="ind" value="delete" onclick="JS({!index});return false;">
              <apex:param assignTo="{!pdtId}" value="delete"/>
                  </apex:commandButton>
                   <apex:variable var="index" value="{!index + 1}" />
              </apex:repeat>
            </apex:pageBlockSection>
        </apex:pageBlock>
                <apex:actionFunction name="Callme" action="{!deleteOpp}" reRender="a">
                    <apex:param id="aname" name="deleteIndex" value="" assignTo="{!deleteIndex}" />
        </apex:actionFunction>
    </apex:form>
    <script>
    function JS(index)
    {
        Callme(index);
     }
    </script>
</apex:page>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.