1

Below is My webservice it is working for account to opportunity insert, when i inserting a quote records it showing an error Insertion is fail error message requried field is missing opportunityId below is my webservice as per my program contact is inserting to particular account,but quotes are not inserting into particulat opportunity.

      for(integer k=0;k<opportunity.k++){
         opp = new Opportunity();
         opp.Name = oName;
         opp.CloseDate =system.today();
         opp.StageName =oStage;
          opp.accountId = id;
          oppList.add(opp);

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

          qList.add(qu);   


      // insert
        insert contactList;
   insert oppList;
   insert qList;
    }
   } 
    }
   }
  • 2
    Can you please fix your code and format it correctly, so that we can help? – James Loghry Dec 27 '13 at 15:18
  • @DancinLlama i updated my code.. – Sathya Dec 27 '13 at 15:28
  • Can you please tell us what you are trying to do exactly? You're cloning the Opportunity (without specifiying an Id). Same with the Quote. Also, if you could provide the entire method, that would also help us help you. – James Loghry Dec 27 '13 at 15:37
3

Sathya - You should post your webservice method in its entirety so we can see what you are trying to accomplish from end-to-end.

At first blush, you are not INSERTing the Opportunities before you are referencing them in your Quote loop. That would be why you're getting the "Missing OpportunityId".

  • I paste my code can you give me suggestions where i have to modify my code. – Sathya Dec 27 '13 at 15:41
  • 1
    Sathya - again please post your code COMPLETELY from method header through the last curly brace. If you don't give us the information to help you, we cannot. – Andy Boettcher Dec 27 '13 at 15:43
  • 1
    Excellent! Ok - so here is the biggest design tenet that you have to keep in mind; you create the references to child objects, you have to insert the parent object fully first. You need to do a full DML insert on your Opportunity list prior to referencing them in your Quote loop. That will get you beyond the error. – Andy Boettcher Dec 27 '13 at 15:47
  • 1
    Because you're waiting to insert everything at the same time at the bottom of your class, you don't have the referencial Opportunity Ids when you are creating the Quote objects - hence the error you're seeing. If you insert the Opportunities PRIOR to creating your quote objects (insert, pull them back in a map so you can key off of them), then create the quote objects you will be good. – Andy Boettcher Dec 27 '13 at 15:49
  • 2
    Exactly - you have to insert first - then pull the newly created opps into a Map so you can key off of them properly in the Quote loop. – Andy Boettcher Dec 27 '13 at 15:50

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.