Solved

Attached Contact to Account

Posted on 2012-03-29
2
425 Views
Last Modified: 2012-04-16
I ma using the code below to add a new contact and attach it to an account.  The contact gets added OK but the parentcustomerid does not seem to get added.


 
Private Function AddNewContact(ParentAccount As Guid, ParentAccountName As String, Firstname As String, Lastname As String, Email As String, Tel As String) As Guid

        Dim newcontact As New Entity()
        newcontact.LogicalName = "contact"

        Dim newcontactColl As New AttributeCollection()
        newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomeridtype", 1))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomeridname", "parentcustomerid"))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomerid", ParentAccount))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("firstname", Firstname))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("lastname", Lastname))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("telephone1", Tel))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("emailaddress1", Email))
        newcontact.Attributes = newcontactColl

        Dim ContactID As Guid
        ContactID = Client.Create(newcontact)

        Return ContactID

    End Function

Open in new window

0
Comment
Question by:Kevin Robinson
2 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 500 total points
ID: 37787056
Hi VolunteerDevelopmentAgency,

newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomeridtype", 1))
newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomeridname", "parentcustomerid"))
newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomerid", ParentAccount))

Open in new window

               

I think it should be like this
newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomerid", new EntityReference("account", parentcustomerid)))

Open in new window


If this code does not work then sorry as I am not comfortable with VB.Net, I have provided a C# style code.

Regards,
Chinmay.
0
 
LVL 3

Author Closing Comment

by:Kevin Robinson
ID: 37850211
Thanks
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
Desired Skill Set for Microsoft Dynamics CRM Technical Resources – Part I

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question