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
asish1989asish1989 

Error in Quote

Hi Everyone

I want to add more product in a perticular Quote.I know the relationship between Quote,QuoteLineItem ,Pricebook2,Product2 and PricebookEntry.my first product is saved but when I am  trying to add more product under a perticular Quote an error is fired.

"Id is not specified in an update call.."  .I have written update statement to update Quote because there is a required field Pricebook2Id in Quote.when I  am creating a new product at that time assisgning a unit price through PricebookEntry.Because Product2 and Pricebook2 are related in a many to many relationship and the junction object is PricebookEntry.

My problem is that how can we update PricebookId field In Quote each time when a Product is created.

That means there is one record in Quote but I have to created more product inside perticular Quote.

 

I am beginner in salesforce.May be I canot express my problem.So I request please help me in a simpler way....

Here is my code.

 

<apex:page controller= pcontactdetailcontroller>

................

...............

 

       <!----QUOTE table-->
  <apex:pageBlockSection title="Quote Details of a Perctcular Opportunity" rendered="{!table=='Show'}">
           
                <B>OPPORTUNITY NAME:&nbsp;{!Opportunity1.Name}</B>
            <!--<apex:outputField label="OPPORTUNITY" value="{!OpportunityContactRoles.Opportunity.Name}"/>-->
              <apex:outputPanel style="float:middle">
                  <p><B> All Quotes </B></P>
                 <apex:dataTable value="{!Opportunity1.Quotes}" var="Qut" cellpadding="2" border="1"  rowClasses="odd,even" >
           
                    <apex:column headerValue="Quote Name">
                    <apex:commandLink value="{!Qut.Name}"  title="to see product" style="font-size:15;color:blue;" action="{!forProduct}">
                     <apex:param name="quoteId" value="{!Qut.Id}"/>
                     </apex:commandLink>
                    </apex:column>
                     <apex:column headerValue="Status">{!Qut.Status}</apex:column>
               
                   </apex:dataTable>
                  </apex:outputPanel>
                  <apex:commandButton value="Add Quote" action="{!toaddQoute}"/>
             </apex:pageBlockSection>

 

 <!--product table------>
                 <apex:pageBlockSection title="Product Details" rendered="{!asish=='Show'}">
            
                  <B>OPPORTUNITY NAME:&nbsp;{!Opportunity1.Name}</B><br/><br/>
                  <B>QUOTE NAME:&nbsp;{!Quote1.Name}</B>
               <apex:outputPanel style="float:middle">
                  <p><B> Product Details </B></P>
                  <apex:datatable value="{!quote1.QuoteLineItems}" var="pdct" cellpadding="2" border="1"  rowClasses="odd,even">
                  <apex:column headerValue="Product Name">{!pdct.PricebookEntry.Product2.Name}</apex:column>
                  <apex:column headerValue="Unit Price">{!pdct.UnitPrice}</apex:column>
                  <apex:column headerValue="Quantity">{!pdct.Quantity}</apex:column>
                  <apex:column headerValue="Sub Total">"{!pdct.Subtotal}</apex:column>
                  <apex:column headerValue="Discount">"{!pdct.Discount}</apex:column>
                  <apex:column headerValue="TotalPrice">{!pdct.TotalPrice}</apex:column>
                  
                  </apex:datatable>
                  
               </apex:outputPanel>
               <apex:commandButton value="Add Product" action="{!toaddProduct}"/>
              
       </apex:pageBlockSection>

.......................

    

         <!--PRODUCT SECTION FOR ENTRY-->
            
            <apex:pageBlockSection title="Product Details" rendered="{!visible=='Step3'}">
            <apex:inputField value="{!Product.Name}"/>
           <!--<apex:inputField value="{!PricebookEntry.UnitPrice}"/>-->
            <apex:inputField value="{!QuoteLineItem.UnitPrice}"/>
            <apex:inputField value="{!QuoteLineItem.Quantity}"/>
             <apex:inputField value="{!QuoteLineItem.Discount}"/>
            <apex:inputCheckbox value="{!PricebookEntry.IsActive}"/>
           
            <apex:commandButton value="save" action="{!tosaveProduct}" style="float:left"/>
            
            </apex:pageBlockSection>

   </apex:page>

here is my controller code.....

 

public class pcontactdetailcontroller {

..................

.................

 public Quote quote{get;set;}

 public PricebookEntry pbentry{get;set;}
     public Pricebook2 pb{get;set;}
     public Product2 product{get;set;}
     public QuoteLineItem qutlineitem{get;set;}

 public Id quoteId{get;set;}

 

 public pcontactdetailcontroller() {

 pb= new Pricebook2();
      pbentry= new PricebookEntry(UseStandardPrice=true,UnitPrice=0.00);
      product=new Product2();
      qutlineitem=new QuoteLineItem();

}

 

 public Quote getQuote() {
       return quote;
       }

public Product2 getProduct2() {
    
        return product;
        }
     public Pricebook2 getPricebook2() {
    
        return pb;
        }
     public PricebookEntry getPricebookEntry() {
    
        return pbentry;
        }
     public QuoteLineItem getQuoteLineItem() {
    
       return qutlineitem;
       }

 

 
    //saving Quote and opening product entry section    
         
    public PageReference tosaveQuote() {
 
       quote.BillingName=contact.Account.Name;
       quote.ShippingName=contact.Account.Name;
       quote.ContactId =contact.Id;
       quote.Phone=contact.MobilePhone;
       quote.Email= contact.Email;
 
      // System.debug('########## quoteOpportunityId######'+ quote.OpportunityId);
       insert quote;
    
       visible='Step3';
   
    // insert quote1;
       return null;
       }
       
    //saving Product   
    
    
   public PageReference tosaveProduct() {
 
       insert product;
 
       pb.Name='Standard';
 
       insert pb;
       pbentry.Product2Id=product.Id;
       pbentry.Pricebook2Id=pb.Id;
    // pbentry.UnitPrice=0.00;  
    // pbentry.UseStandardPrice=true;
   
       insert pbentry;
       quote.Pricebook2Id=pb.Id;
       update quote;
       qutlineitem.PricebookEntryId = pbentry.Id;
       qutlineitem.quoteId=quote.Id;
       insert qutlineitem;
       visible=null;
       Id Id = ApexPages.currentPage().getParameters().get('Id');
       PageReference samepage= new PageReference('/apex/pcontactdetail?id='+id);
       samepage.setRedirect(true);
       return  samepage;
   }

 

 public PageReference forProduct() {
    
       quoteId = ApexPages.currentPage().getParameters().get('quoteId');
      quote1= [select Id,Name,(select Id,PricebookEntry.Product2.Name,UnitPrice,Quantity,Subtotal,Discount,TotalPrice From QuoteLineItems) from Quote where Id=:quoteId];
    
     asish = 'Show';
      return null;
   }

 public PageReference toaddProduct() {
       visible = 'Step3';
       return null;
       }
  }

I have sent necessary code at which I am facing problem.I have faced problem in the line

Update Quote;

kindly reply me as soon as possible...

 

Best Answer chosen by Admin (Salesforce Developers) 
BussBuss

i think you are correct.already one ProceBook is selected for this quote(Opportunity) again you are selecting one more for this quote, So it is wrong. Based on below statement.

at a time one PriceBook is enabled for a Opportunity you cann't select morethan one Pricebook for a Opportunity.

So you can add more products of one PriceBook to a Quote.

 

Sorry for helpless.

i am also same like you Salesforce.

 

Reds,

Buss

 

All Answers

BussBuss

HI asish,

 

it may becuase you are used same object to insert and update while updating it refering the same Memory which is used for Insert. My Suggestion is take new Quote Object and Query in tosaveProduct() and perform your update logic.

 

Reds,

Buss

asish1989asish1989

Hi

I tried by making a new variable quote1 in Quote but still I am facing same Problem.I want to know how can we update multiple value in a singly field.when I am creating a new product each product is associated with a pricebook2Id through PricebookEntry object and also there is a required field "PricebookId" in Quote, In order to save Product and Price In Product under Quote we have to update PricebookId in Quote.that is  

quote.PricebookId = pricebook.Id;

update quote;

In this way first product is saved under particular Quote.When I am creating another product under same Quote then error is fired Invalid Id for Update call.....

I think there is one record in Quote table.PricebookId field has one value.so when I create another product under same Quote

then PricebookId field has allready a value.how can this field contain multi value for one record in Quote.Because each time we have to update PricebookId in Quote when a product is created.

As for my understanding I have expressed my problem clearly...so kindly help me  if anyone have suggession.

 

with Regards

asish

 

BussBuss

i think you are correct.already one ProceBook is selected for this quote(Opportunity) again you are selecting one more for this quote, So it is wrong. Based on below statement.

at a time one PriceBook is enabled for a Opportunity you cann't select morethan one Pricebook for a Opportunity.

So you can add more products of one PriceBook to a Quote.

 

Sorry for helpless.

i am also same like you Salesforce.

 

Reds,

Buss

 

This was selected as the best answer