Solved

CRM 3.o SDK and creating a Contact object.

Posted on 2006-11-14
2
987 Views
Last Modified: 2013-11-24
Hi,

I have written this piece of code using C# and Visual Studio 2005.

I want to be able to create a contact object  for every Account object that I create for Microsoft CRM 3.0


My C# code is listed below.

With this code, CRM web Service will throw an Exception.
if I were to comment out these two lines from the code.

            objContact.parentcustomerid = new Customer();
            objContact.parentcustomerid.Value = new Guid(custID);

the code will execute without throwing any exceptions, but then the contact which gets created does not have its Parent Account set. What I want to do is have a Contact object created for every Account I create.

How do I correct these two lines of code so that no exceptions are thown and Contacts gets it Parent Account assigned.
 




            CrmService service = new CrmService();
            service.Credentials = System.Net.CredentialCache.DefaultCredentials;
            service.Timeout = 3000 * 10000;
            service.PreAuthenticate = false;

            // Create the account object.
            contact objContact = new contact();

            // Set the properties of the account object.
            objContact.firstname = fname;
            objContact.lastname = lname;
            objContact.emailaddress1 = eaddress;

            // Assign Parent CustomerId for contact.
            objContact.parentcustomerid = new Customer();
            objContact.parentcustomerid.Value = new Guid(custID);

            String ListId = getContactID(fname, lname);

            if ((ListId.CompareTo("empty")) != 0)
            {
                // contact already exist
                return;
            }
            else
            {
                // does not exist. So will add a new contact object
            }
           

            // Create the target object for the request.
            TargetCreateContact target = new TargetCreateContact();

            // Set the properties of the target object.
            target.Contact = objContact;

            // Create the request object.
            CreateRequest create = new CreateRequest();

            // Set the properties of the request object.
            create.Target = target;

            // Execute the request.
            CreateResponse created = (CreateResponse)service.Execute(create);


0
Comment
Question by:nitadmin
2 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
ID: 17948867
You need to set the entity type as well as the ID.

try this:

            objContact.parentcustomerid = new Customer();
            objContact.parentcustomerid.type = new EntityName.account.ToString();
            objContact.parentcustomerid.Value = new Guid(custID);
0
 
LVL 8

Author Comment

by:nitadmin
ID: 17949036
This is what I was missing.

 objContact.parentcustomerid.type = new EntityName.account.ToString();

thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Accounting ERP with security issue 5 302
Windows Server 2003 migration & SAGE 3 88
CRM 2011 Deployment Package 2 152
snapshot of lead status on a daily basis 5 147
Hello All, In previous article we used Hortonworks sandbox to work with Hadoop. Now, lets think to create own single node Hadoop on Linux. Here we Install and Configure Apache Hadoop on UI based Oracle Linux. I assume, you have VMware installe…
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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