Try our conversational search powered by Generative AI!

Episerver Connect for CRM; no phone field available for saving a contact?

Vote:
 

Hello,

I'm currently working on saving contact information into SalesForce, but I'm encountering two seperate issues. The first, is simply that there doesn't seem to be any way to get the AccountId [to pass to the contact] from the LoadAccountsByName function without piping it through the crm's AccountList dropdown.

Secondly, only a couple of the contact fields appear to be functioning. In particular, I can't seem to get any phone numbers to save [using the following as a CRMFieldName lookup: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_contact.htm ]

The following is a stripped down version of the code I pulled from the crm template example with Alloy tech. This is completely working, except for the issues stated above. If I remove the ValidatedTextBox with the Phone crmfiledname, everything runs fine. Otherwise, it will throw an object ref not set error:

        <h3>Create Contact</h3>
        UserName: 
        <crm:ValidatedTextBox runat="server" ID="ContactUserName" CRMFieldName="UserName" Hidden="True"
            MaxLength="100" />
        Email:
        <crm:ValidatedTextBox runat="server" ID="ContactEmail" CRMFieldName="Email" MaxLength="100" />
        FirstName:
        <crm:ValidatedTextBox runat="server" ID="ContactFirstName" CRMFieldName="FirstName"
            Required="true" 
            LabelCssClass="LabelCss" MarkCssClass="MarkCss" ErrorCssClass="ErrorCss" InputCssClass="InputCss"
            ContainerCssClass="ContainerCss" CssClass="RegistrationItem" MaxLength="50" />
        LastName:
        <crm:ValidatedTextBox runat="server" ID="ContactLastName" CRMFieldName="LastName"
            Required="true" 
            LabelCssClass="LabelCss" MarkCssClass="MarkCss" ErrorCssClass="ErrorCss" InputCssClass="InputCss"
            ContainerCssClass="ContainerCss" CssClass="RegistrationItem" MaxLength="50" />
        JobTitle:
        <crm:ValidatedTextBox runat="server" ID="ContactJobTitle" CRMFieldName="JobTitle"
            LabelCssClass="LabelCss" MarkCssClass="MarkCss" ErrorCssClass="ErrorCss" InputCssClass="InputCss"
            ContainerCssClass="ContainerCss" CssClass="RegistrationItem" MaxLength="100" />
        Phone:
        <crm:ValidatedTextBox runat="server" ID="ContactPhone" CRMFieldName="Phone"
            LabelCssClass="LabelCss" MarkCssClass="MarkCss" ErrorCssClass="ErrorCss" InputCssClass="InputCss"
            ContainerCssClass="ContainerCss" CssClass="RegistrationItem" MaxLength="100" />
        Country:
        <crm:CountryList ID="ContactCountry" CRMFieldName="Country" 
            runat="server" Required="true" 
            LabelCssClass="LabelCss" MarkCssClass="MarkCss" ErrorCssClass="ErrorCss" InputCssClass="InputDropDownCss"
            ContainerCssClass="ContainerCss" CssClass="RegistrationItem" MaxLength="50"/>
        Company:
        <crm:ValidatedTextBox runat="server" ID="AccountName" CRMFieldName="Name"
            Required="true"
            LabelCssClass="LabelCss" MarkCssClass="MarkCss" ErrorCssClass="ErrorCss" InputCssClass="InputCss"
            ContainerCssClass="ContainerCss" CssClass="RegistrationItem" MaxLength="50" />
        <crm:ValidatedTextBox runat="server" ID="ContactAccountId" CRMFieldName="AccountId"
            Hidden="true" MaxLength="50" />
        <asp:Button runat="server" ID="btnCreateContact" OnClick="CreateContactClick" Text="Create Contact"/>

    

    

    C# Click Event:

            //Create or pull an account based off of the company name field.
            var accountSetters = new List<ICRMFieldSetter> {AccountName};

            var account = Factory.LoadAccountsByName(AccountName.Text).FirstOrDefault();
            var accountList = new AccountList();
            
            ContactAccountId.Text = account == null ? Factory.CreateAccount(accountSetters) : string.Empty; //Instead of string.Empty, I would want something like account.ID

            var contactSetters = form1.Controls.OfType<ICRMFieldSetter>().Where(x=>x.CRMFieldName != "Name");
            var contactId = Factory.CreateContact(contactSetters, "Low, Medium");

            PlaceHolder1.Controls.Add(new LiteralControl("<h2>Contact ID: " + contactId + "</h2>"));

    

 

So;

Question 1: Is there any way to get the AccountID from an existing account through looking up its name?:

Question 2: Is there some other way or field I need to use in order to save the phone number into the contact info? [AssistantPhone, MobilePhone, HomePhone, etc. all throw similar errors.]

#59349
Jun 01, 2012 22:59
Vote:
 

Found the answer to Question 2: 

I simply needed to add the phone field mapping into the Web.Config: 

<crmConnector current="SalesForce" cacheTime="0">
<crms>
<add name="SalesForce" userName="#####" password="####" interfaceUrl="####" timeout="30000">
<entities>

...
<add name="Contact" crmName="Contact" idAttribute="Id">
<attributes>

...
<add name="Phone" crmName="Phone" />

    

#59350
Edited, Jun 01, 2012 23:09
Vote:
 

Hello Morgan,

There is an Id property for all entities, representing an idnetity of the entity in SalesForce: 

ContactAccountId.Text = account == null ? Factory.CreateAccount(accountSetters) : account.Id;

If you need a value of property named "AccoundID", than you can use something like this: 

ContactAccountId.Text = account == null ? Factory.CreateAccount(accountSetters) : account["AccountID"];

 

#59356
Jun 04, 2012 9:06
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.