简体   繁体   English

Salesforce:从C#中创建商机订单项以及商机

[英]Salesforce: create Opportunity Line Items along with Opportunity from C#

using Salesforce's enterprise wsdl I am trying to save opportunity line items along with opportunity. 我使用Salesforce的企业wsdl尝试保存机会订单项以及机会。 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. INVALID_FIELD:实体'Opportunity'上没有此类列'OpportunityLineItems'如果尝试使用自定义字段,请确保在自定义字段名称后附加'__c'。 Please reference your WSDL or the describe call for the appropriate names. 请参考您的WSDL或describe调用以获取适当的名称。

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. oppLineItems是一个词典,整个值具有机会订单项的代理对象。 sfOpportunity is proxy object of Opportunity which is then sent to Salesforce. sfOpportunity是机会的代理对象,然后将其发送给Salesforce。

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 这里有一个非常类似的问题,虽然不确定我们是否应该将其标记为重复: Salesforce:在PHP中创建OpportunityLineItems作为Opportunity的一部分

OpportunityLineItems on Opportunity isn't a real field. OpportunityLineItems上的OpportunityLineItems不是真实字段。 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? 而且HasOpportunityLineItem是一个只读字段:)而且我不认为这些应该是QueryResult ,请查看http://www.salesforce.com/us/developer/docs/api/Content/sample_create_call.htm以获得一些提示?

You will need to insert the Opportunity first, the operation result will give you the record's Id. 您将需要先插入机会,操作结果将为您提供记录的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. 这意味着2个API调用和Opp标头保存确定但一行或多行失败时的额外注意事项...因此,像在另一个问题中建议的那样编写Apex Web服务也许是个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM