I'm getting user name and mail id through sitecore form. on clicking submit the sitecore form submit action has to get triggered. In turn the following code has to get triggered. But the debug point is not hitting. But its showing the thank you message which i have mentioned in the sitecore form. I need to create a contact using the given user credentials which i'll be viewing in Experience profile. Since the code is not getting triggered the contacts are not getting saved so i can't view them in Experience Profile. Kindly suggest me some solutions. Thanks in advance.
public class LoginFormSubmit : SubmitActionBase<string>
{
public LoginFormSubmit(ISubmitActionData submitActionData) : base(submitActionData)
{
}
protected override bool TryParse(string data, out string target)
{
target = string.Empty;
return true;
}
//Override the Execute method to insert data to API
protected override bool Execute(string data, FormSubmitContext formSubmitContext)
{
ApiModel customData = new ApiModel();
try
{
Log.Info("FormSubmit Execute Method Started..", typeof(FormSubmit));
var firstNameField = GetFieldByName(ApiConstants.FirstName, formSubmitContext.Fields);
customData.First_Name__c = GetValue(firstNameField);
var emailField = GetFieldByName(ApiConstants.Email, formSubmitContext.Fields);
customData.Email__c = GetValue(emailField);
CreateContact contact = new CreateContact();
contact.CreateContactBasedOnSession(customData.First_Name__c, customData.Email__c);
return true;
}
catch (Exception e)
{
Log.Error("Login Save:", e, typeof(FormSubmit));
Log.Error(string.Concat("Login save", e.Message.ToString()), typeof(FormSubmit));
return false;
}
}
private static IViewModel GetFieldByName(string fieldName, IList<IViewModel> fields)
{
return fields?.FirstOrDefault(f => f.Name == fieldName) != null ? fields.FirstOrDefault(f => f.Name == fieldName) : null;
}
private static string GetValue(object field)
{
return field?.GetType().GetProperty("Value")?.GetValue(field, null)?.ToString() ?? string.Empty;
}
}