1

I have a wrapper class that has a QuoteLineItem and a Product2, and that wrapper is a list. The wrapper is used in a quotelineitem editor, but I am not sure how i would update the objects. I tried something like this:

public void updateWrapper(){
    update wrapper.wQli;
    update wrapper.wProd;
}

but the error i get says I can't update a non-SObject. any idea how to go about this problem?

2

Mike you can not do DML operations on Wrapper class, you need to be specific on which object you are going to perform DML operation. Suppose you have QutoelineItem and product2 in the wrapper and you need to update only specific records form the Wrapper list then loop through the wrapper list and collect the records of both objects into two different lists of quotelineitem object and product2 which satisfies your requirement.

0

Extract your sObjects from the wrapper - by assigning to a regular list of sObjects or just a single sObject. Then update that.

As long as the update method sees a plain sObject it'll update fine.

In your method, you could change the code to this:

public void updateWrapper(){
    QuoteLineItem qli = wrapper.wQli;
    Product2 prod = wrapper.wProd;
    update qli;
    update prod;
}

If you are using a list, you do it like this:

List<QuoteLineItem> quoteLineItemsToUpdate = new List<QuoteLineItem>();

Then loop through your wrapper and add to your list. Finally call Database.update(quoteLineItemsToUpdate,false); or update quoteLineItemsToUpdate

0

Without code it is hard to say what you are doing wrong. But to show an example that would work according to how your question is structured it would look something like this:

public class exampleClass{

  public exampleWrapper[] wrap {get;set;}

  public exampleClass(){
     wrap.add(New exampleWrapper(New Account());
  }

  public void updateAccounts(){

     Account[] accts = New Account[]{};

     for(exampleWrapper w : wrap)
        accts.add(w.a);

     update accts;

  }


  public class exampleWrapper{
     public Account a {get;set;}

     public exampleWrapper(Account acc){

        a = acc;

     }

  }

}

Of course this is only a mock up and not a complete example as the sObjects fields are not populated, etc.

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.