Find your content:

Search form

You are here

MISSING_ARGUMENT, Id not specified in an update call

 
Share

On button click on opportunity... I am showing opportunityline items records on a page with line number using repeat.

I have used wrapper class for showing line number.

My Problem

Opportunityline items fields are editable on page..so user can update them...i am having problem updating it...How to specify id for updating...

in Constructor

List<OpportunityLineItem> oli;
oli=[Select Id,opportunityId From OpportunityLineItem where opportunityId=:id];
showsavedoppLineitems();

wrapper class

public list<linenumberclass> wrapperopllist;//List used in repeat on page
public Class linenumberclass{
public integer lineNumber{get;set;}
public OpportunityLineItem oppLineNo{get;set;}



 public linenumberclass(OpportunityLineItem oppLineNo,Integer lineNumber){
    this.oppLineNo=oppLineNo;
    this.lineNumber=lineNumber;
  }

}

method called from constructor

public void showsavedoppLineitems(){   

List<OpportunityLineItem> lOpp=[select   id,Business_Type__c,pricebookentry.pricebook2id,pricebookentryid from OpportunityLineItem where id in:opplineIttems]; 

  for(OpportunityLineItem l:lOpp){    
     opline = new OpportunityLineItem ();
     opline.OpportunityId=id;
     opline.pricebookentry=pre.get(l.pricebookentryid);
     opline.pricebookentryid=l.pricebookentryid;
     opline.Territory1__c=l.Territory1__c;
     wrapperopllist.add(new linenumberclass(opline,m));
      m++;
  }
}

i am calling this method on button click...so i have the updated record value in oplist...

public list<OpportunityLineItem> opllist {get;set;}

public void add {

    for(linenumberclass ln:wrapperopllist) {
        opline = new OpportunityLineItem ();
        opline.opportunityid=id;
        opline.PricebookEntry=ln.oppLineNo.pricebookentry;
        opline.PricebookEntryid=ln.oppLineNo.pricebookentryid;
        opline.Line__c=ln.linenumber;
        opllist.add(opline);
    }

}

i dont know how to update oplist....

As i am showing the records in editable mode...if any user edits them and click on them records should be updated .

i dont know how to update existing records.i dont how to pass id.


Attribution to: Mik

Possible Suggestion/Solution #1

If i understand correctly you are trying to update the record after user interaction (after edit) and your problem is you have a wrapper list.

for(linenumberclass ln:wrapperopllist){
   opline = new OpportunityLineItem ();
   **opline.opportunityid=ln.oppLineNo.opportunityid**;//added the proper code here
   opline.PricebookEntry=ln.oppLineNo.pricebookentry;
   opline.PricebookEntryid=ln.oppLineNo.pricebookentryid;
   opline.Line__c=ln.linenumber;
   opllist.add(opline);
}
   update opllist;

Also please dont make any DML calls inside the constructor .

Note please query the opportunityId field too else you will run into exception saying sobject row was retrieved without querying the field .


Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #2

Your issue is that you are not retaining the queried OpportunityLineItem records, which contain the Id needed to update them later.

Instead you appear to be creating for each item in your wrapped list a brand new OpportunityLineItem record and passing that into your wrapper. These do not have an Id (nor can you 'easily' be assign one) by default. Typically you only create new objects if you intend to perform inserts.

So my suggestion is to simply pass 'l' into your 'linenumberclass' constructor. This also saves you having to copy across field values.

for(OpportunityLineItem l:lOpp){    
    wrapperopllist.add(new linenumberclass(l,m));
    m++;
}

Also when updating make sure once again to use the instance of the record you originally queried to populate your list of OpportunityLineItem's to update.

for(linenumberclass ln:wrapperopllist){
    opllist.add(ln.oppLineNo);
}

Then...

update opllist;

UPDATE: In your original code you are utilising the 'pre' variable when creating OpportunityLineItem. Which as you say in the comments is a map of PricebookEntries. You can often obtain related information by using the relationships between the objects in your queries and save yourself code and SOQL requests. For example to retrieve the Product name, add 'pricebookentry.product2.name' like so...

List<OpportunityLineItem> lOpp=
    [select id,
       Business_Type__c, 
       pricebookentry.product2.name,
       pricebookentry.pricebook2id,
       pricebookentryid 
     from OpportunityLineItem 
     where id in:opplineIttems]; 

Should work, hope this helps.


Attribution to: Andrew Fawcett
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4258

My Block Status

My Block Content