Skip to main content
added 685 characters in body
Source Link
Andrew Fawcett
  • 40.7k
  • 5
  • 100
  • 127

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.

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;

Should work, hope this helps.

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.

added 91 characters in body
Source Link
Andrew Fawcett
  • 40.7k
  • 5
  • 100
  • 127

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;

Should work, hope this helps.

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 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.

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;

Should work, hope this helps.

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;

Should work, hope this helps.

Source Link
Andrew Fawcett
  • 40.7k
  • 5
  • 100
  • 127

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 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.

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;

Should work, hope this helps.