Hi all,
Pleaes find the Below code for Creating Lead and Adding that user into activity party List
createLead("test;test",service,from);
public static void createLead(string splitString, IOrganizationService service, string fieldName, Entity target)
{
string[] arrayfromtextEmail = splitString.Split(';');
EntityCollection collectionEmailAddress = new EntityCollection();
foreach (string loopWord in arrayfromtextEmail)
{
Guid getLeadID = checkEmailIDExisits(service, loopWord);
if (getLeadID == Guid.Empty)
{
Lead createLead = new Lead();
createLead.FirstName = loopWord.Substring(0, loopWord.IndexOf("@"));
createLead.EMailAddress1 = loopWord;
getLeadID = service.Create(createLead);
}
Entity Emailparty = new Entity(ActivityParty.EntityLogicalName);
Emailparty["addressused"] = loopWord;
Emailparty["partyid"] = new EntityReference(Lead.EntityLogicalName, getLeadID);
collectionEmailAddress.Entities.Add(Emailparty);
}
target[fieldName] = collectionEmailAddress;
}
Pleaes find the Below code for Creating Lead and Adding that user into activity party List
createLead("test;test",service,from);
public static void createLead(string splitString, IOrganizationService service, string fieldName, Entity target)
{
string[] arrayfromtextEmail = splitString.Split(';');
EntityCollection collectionEmailAddress = new EntityCollection();
foreach (string loopWord in arrayfromtextEmail)
{
Guid getLeadID = checkEmailIDExisits(service, loopWord);
if (getLeadID == Guid.Empty)
{
Lead createLead = new Lead();
createLead.FirstName = loopWord.Substring(0, loopWord.IndexOf("@"));
createLead.EMailAddress1 = loopWord;
getLeadID = service.Create(createLead);
}
Entity Emailparty = new Entity(ActivityParty.EntityLogicalName);
Emailparty["addressused"] = loopWord;
Emailparty["partyid"] = new EntityReference(Lead.EntityLogicalName, getLeadID);
collectionEmailAddress.Entities.Add(Emailparty);
}
target[fieldName] = collectionEmailAddress;
}