while working with webservice quotes are not inserting may i know what i have to do. my code is

   for(integer l=0;l<reqquotes;l++){
         qu = new Quote();
         qu.Name = qName;
         //opp.CloseDate =system.today();

         insert oppList;
         insert qList;

1 Answer 1


For starters, your class is private (default) and should be set to public or global.

Next you're creating a list of accounts (accList) that consists of new and existing accounts. Then you try to insert that list when an upsert is what's called for. Since you're doing a Database.insert(false) on accList, all of those accounts that should be updated as opposed to inserted are failing silently.

Then there's the problem of trying to use the ids of items before they're created:

You need to change the order of execution here. First insert the oppList and then you can use their ids.

But a more concerning issue with this code is that you're attempting to insert all three lists at every iteration of a for loop that's the third loop in a nest! I had to straighten out the code to see it, but this is a big problem:

for(integer l=0;l<quotes.size();l++) // *** LOOP #3 ***
                qu = new Quote();


Your logic is adding items to these lists in the outer loops and then attempting to insert the lists at each iteration of your innermost loop. This is not just a problem in terms of logic, but it's also going to cause you to hit governor limits.

As a general recommendation, it helps if you describe what you're seeing. Is it an error message? Is it not calling the method at all? Is it executing without error yet no data is being inserted? etc.

  • May i know where i have to modify my code to overcome this problem.
    – Sathya
    Commented Dec 30, 2013 at 7:08
  • 1. Create and upsert your accounts. 2. Create and insert your contacts and opportunities. 3. Create and insert your quotes. Don't do DML inside of loops. Create them inside of loops but insert them outside of loops.
    – Adam
    Commented Dec 30, 2013 at 16:03
  • I rectify my problem.could plz help me Product insert question .
    – Sathya
    Commented Dec 30, 2013 at 16:08
  • 1
    Sathya, make sure to mark correct answers as correct. Also, Looking at your code I think it would be very helpful if you took a step back and spent some time learning SOQL, DML and Apex development in general. Go to developer.force.com and start with the workbooks and move on to the Force.com books. If you plan to continue Force.com development, it's the best investment you can make.
    – Adam
    Commented Dec 30, 2013 at 17:05

Not the answer you're looking for? Browse other questions tagged .