使用c#为salesforce中的新联系人添加附件

时间:2012-09-21 05:58:16

标签: c# salesforce

我们需要为新联系人添加附件。我们使用APEX类添加新联系人。我们可以创建新的联系人。我们需要维护联系人的订单信息。使用可用字段/自定义字段无法做到这一点。所以我们将尝试附件。客户可能有多个订单。 您能否告诉我如何使用c#为联系人添加附件。

请找到以下代码段:

Contact newContact = new Contact();

newContact.LastName = downloadInformation.Name;
newContact.Email = downloadInformation.Email;

try
{
    SforceService salesForce = new SforceService();
    MySFServiceService mySFServive = new MySFServiceService();
    mySFServive.SessionHeaderValue = new SForce.MyService.SessionHeader();

    LoginResult loginResult = salesForce.login("id", "password");
    mySFServive.SessionHeaderValue.sessionId = loginResult.sessionId;
    // UserRegistration is a method defined in our apex class.
    // parametter 1: contact object parameter
    // 2: account name
    mySFServive.UserRegistration(newContact, "Test Account");
}
catch (Exception ex)
{
}

1 个答案:

答案 0 :(得分:3)

将企业WSDL导入您的应用程序(看起来您已经拥有),然后创建附件对象的实例,将其主体设置为订单blob,并将parentId设置为联系。因此,您需要更新自定义的UserRegistration调用以返回创建的contactId,然后就可以了。

salesforce.SessionHeaderValue = new SforceService.SessionHeader();
salesforce.SessionHeaderValue.sessionId = loginResult.sessionId;
salesforce.Url = loginResult.serverUrl;
...
String contactId = mySFervive.UserRegistration(....);
Attachment a = new Attachment();
a.Body = readFileIntoByteArray(someFile);
a.parentId = contactId;
a.Name = "Order #1";

SaveResult sr = salesforce.create(new SObject [] {a})[0];
if (sr.success){ 
// sr.id contains id of newly created attachment
} else {
 //sr.errors[0] contains reason why attachment couldn't be created.
}
相关问题