0
votes

using Salesforce's enterprise wsdl I am trying to save opportunity line items along with opportunity. But I am getting following error:

INVALID_FIELD: No such column 'OpportunityLineItems' on entity 'Opportunity' If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Here is my code to create line items:

if (oppLineItems.Count > 0)
{
     sfOpportunity.OpportunityLineItems = new QueryResult();
     sfOpportunity.HasOpportunityLineItem = true;
     sfOpportunity.OpportunityLineItems.records = oppLineItems.Values.ToArray();

     Pricebook2 priceBook = new Pricebook2();
     priceBook.PricebookEntries = new QueryResult();
     priceBook.PricebookEntries.records = new List<PricebookEntry>() { priceBookEntry }.ToArray();
     sfOpportunity.Pricebook2 = priceBook;
}

oppLineItems is a dictionary whole values have proxy objects of opportunity line items. sfOpportunity is proxy object of Opportunity which is then sent to Salesforce.

1

1 Answers

1
votes

There's a very similar question here, not sure if we should mark it as duplicate though: Salesforce: Creating OpportunityLineItems as part of the Opportunity in PHP

OpportunityLineItems on Opportunity isn't a real field. Its something called "relationship name"... Similar to table alias in normal databases, useful especially when you're making joins. And HasOpportunityLineItem is a readonly field :) And I don't think these should be QueryResult, check http://www.salesforce.com/us/developer/docs/api/Content/sample_create_call.htm for some hints?

You will need to insert the Opportunity first, the operation result will give you the record's Id. Then you should insert a list (array) of the line items.

This means 2 API calls and extra considerations what to do when the Opp header saves OK but one or more lines fails... So maybe it's good idea to write an Apex webservice like I suggested in that other question.