Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

This question already has an answer here:

I am using following webservice but my quotes are not inserting it showing an error may i know how to modify my code. for insert of quotes. Can anyone give me suggestions how to modify my code for quote insert. while inserting it showing an error opportunity Id filed missing

           for(integer j=0;j<req.accounts[i].quotes.size();j++)
           {
            qu = new Quote();
            qu.Name = req.accounts[i].quotes[j].qName;
           // op.CloseDate =system.today();
           // op.StageName = req.accounts[i].opps[j].oStage;
            qu.OpportunityId = srList[i].id;
            qList.add(qu); 
           }
            Database.insert(qList);  

        }
       }
         return res;
     }
}
share|improve this question

marked as duplicate by Adam, sfdc_ninja, Mike Chale, James Loghry, mast0r Dec 30 '13 at 21:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 4 down vote accepted

When inserting quote in sfdc its important and mandatory to associate the Opportunity to the quote .

In your code for opportunity Id for quote i am seeing you are not populating the Id properly ,

for(integer j=0;j<req.accounts[i].quotes.size();j++){
        qu = new Quote();
        qu.Name = req.accounts[i].quotes[j].qName;
        qu.OpportunityId = oppList[i].id;//important to populate this .In your code i see you have Account Id instead .
        qList.add(qu); 
       }
share|improve this answer
    
once you replace with opportunity Id as we have suggested things will work –  Mohith Shrivastava Dec 30 '13 at 13:41
    
The context of question is different .Describe in next question to get proper attention –  Mohith Shrivastava Dec 30 '13 at 13:59
    
i post a new question can you give me suggestions.for product insert i update the code also. –  Sathya Dec 30 '13 at 14:13

The problem is in your last for loop, when you're trying to populate qu.OpportunityId. You have

qu.OpportunityId = srList[i].id;

But srList is holding results from when you inserted Accounts, not Opportunities, so you aren't correctly populating the field.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.