Liebe Community,
ich habe folgendes Problem und hoffe, dass ich hier eine Antwort finde.
Es geht um Plug-Ins und um die Erstellung eines Kontaktes, einer Firma und einer Verkaufschance ausgehend vom Lead.
Das Plug-In startet, wenn eine bestimmte Aufgabe als Abgeschlossen gespeichert wird.
Da der Nachname im Lead ein Pflichtfeld ist lege ich zunächst einen Kontakt an:
contact new_Contact = new contact();
Guid new_Contact_Guid = Guid.Empty;
if (context.IsExecutingInOfflineMode) { new_Contact.contactid = new Key(Guid.NewGuid());
if (retrievedLead.Properties.Contains("lastname"))
{
new_Contact.lastname = retrievedLead.Properties["lastname"].ToString();
...und noch einige andere Attribute
}
new_Contact_Guid = service.Create(new_Contact);
In new_Contact_Guid steht die GUID des neuen Kontaktes drin.
Soweit so gut....
Als nächstes die Firma:
account new_Account = new account();
Guid new_Account_Guid = Guid.Empty;
if (context.IsExecutingInOfflineMode) { new_Account.accountid = new Key(Guid.NewGuid()); }
if (retrievedLead.Properties.Contains("companyname"))
{
new_Account.name = retrievedLead.Properties["companyname"].ToString();
.... s.O.
//Nun wird dem Account der Kontakt übergeben und als PrimaryContact gespeichert
if (new_Contact_Guid != Guid.Empty)
{
Lookup primaryContact = new Lookup();
primaryContact.type = EntityName.contact.ToString();
primaryContact.Value = new_Contact_Guid;
new_Account.primarycontactid = primaryContact;
}
}
new_Account_Guid = service.Create(new_Account);
Bis hierhin funktioniert auch noch alles:
Anschließend soll dem Kontakt die frisch erzeugte Firma zugewiesen werden:
if (new_Account_Guid != Guid.Empty)
{
contact contact = new contact();
Customer parentCustomer = new Customer();
parentCustomer.Value = new_Account_Guid;
parentCustomer.name = EntityName.account.ToString();
contact.parentcustomerid = parentCustomer;
contact.contactid = new Key();
contact.contactid.Value = new_Contact_Guid;
TargetUpdateContact targetContact = new TargetUpdateContact();
targetContact.Contact = contact;
UpdateRequest update = new UpdateRequest();
update.Target = targetContact;
//so, und bei der Nächsten Zeile erhalte ich den Automation Sales Force-Fehler.
UpdateResponse updated = (UpdateResponse)service.Execute(update);
}
//Die Fehlermeldung sagt weiterhin aus, dass das angeforderte Kontakt nicht existiert, was vollkomender quatsch ist, da er sehr wohl existiert.
###############################################################
Punkt 2: Ungülitges Argument!
Wenn ich jetzt die Verbindung auskommentiere und mit der Verkaufschance weitermachen möchte erhalte ich den Fehler beim Create, Ungültiges Argument.
opportunity new_Opportunity = new opportunity();
Guid new_Opportunity_Guid = Guid.Empty;
if (context.IsExecutingInOfflineMode) { new_Opportunity.opportunityid = new Key(Guid.NewGuid()); }
new_Opportunity.name = retrievedLead.Properties["subject"].ToString();
new_Opportunity.transactioncurrencyid = Currency;
//Currency ist vom Typ Lookup und dort steht die Währung aus dem Lead drin
new_Opportunity.customerid = new Customer();
new_Opportunity.customerid.name = EntityName.account.ToString();
new_Opportunity.customerid.Value = new_Account_Guid;
new_Opportunity_Guid = service.Create(new_Opportunity);
Vielleicht kann mir jemand einen Tipp geben was ich falsch mache?!
Viele Grüße,
Sascha