Sample code for Inserting a lead record from a .NET application : Oracle CRM On Demand


First download the wsdl file for the lead record from Oracle CRM On Demand web application.

Add web references to it within a .NET windows application.

Use the following code for inserting the lead record.

We need to specify value for all the required field for the record to get inserted.

        String loginUrlString = "https://secure-ausomxapa.crmondemand.com/Services/Integration?command=login";
        String logoffUrlString ="https://secure-ausomxapa.crmondemand.com/Services/Integration?command=logoff";
        String siebelUserName = "username/password";
        String siebelPassword ="password";
        String opportunityUrl = "https://secure-ausomxapa.crmondemand.com/Services/Integration;jsessionid=";
        String sessionID = "";
      
        Private void Form1_Load(Object sender, EventArgs e)
        {            
            // Get the session from the helper Class ManageSession
             sessionID = ManageSession.Login(loginUrlString, siebelUserName, siebelPassword);

            //Create the New lead record instandce And Set its url With proper session id
             Lead myLead = New Lead();
             myLead.Url = "https://secure-ausomxapa.crmondemand.com/Services/Integration;jsessionid=" + sessionID;

            // create arrary Of lead record To be inserted
             LeadData[] myLeadData = New LeadData[1];
             myLeadData[0] = New LeadData();
             myLeadData[0].LeadFirstName = "Nishant";
             myLeadData[0].LeadLastName = "Rana";
             myLeadData[0].Source = "Email";
             myLeadData[0].dLead_Generation_Date = Convert.ToDateTime("7/30/2010");
             myLeadData[0].LeadOwner = "Nishant Rana";
             myLeadData[0].dLead_Generation_dateSpecified = True;             

            // add lead data array To listofLeadData Class
             ListOfLeadData myLstLeadData = New ListOfLeadData();
             myLstLeadData.Lead = myLeadData;

            // create an instance Of leadinsert_input Class
            LeadInsert_Input myLeadRecordInput = New LeadInsert_Input();
            myLeadRecordInput.ListOfLead = myLstLeadData;
            LeadInsert_Output myLeadRecordOutput = myLead.LeadInsert(myLeadRecordInput);    
        }

 

 

The sample code for the ManageSession.cs class

 class ManageSession
    {
        public static string SessionID = "";
        public static String Login(String loginUrlString, String userName, String password)
        {
            try
            {
                // create a http request and set the headers for authentication
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(loginUrlString);
                HttpWebResponse myResponse;
                myRequest.Method = "POST";
                // passing username and password in the http header 
                // username format if it includes slash should be the forward slash /
                myRequest.Headers["UserName"] = userName;
                myRequest.Headers["Password"] = password;
                myResponse = (HttpWebResponse)myRequest.GetResponse();
                Stream sr = myResponse.GetResponseStream();
                // retrieve session id
                char[] sep = { ‘;’ };
                String[] headers = myResponse.Headers["Set-Cookie"].Split(sep);
                for (int i = 0; i <= headers.Length – 1; i++)
                {
                    if (headers[i].StartsWith("JSESSIONID"))
                    {
                        sep[0] = ‘=’;
                        SessionID = headers[i].Split(sep)[1];
                        break;
                    }
                }
                sr.Close();
                myResponse.Close();
            }
            catch (WebException webException)
            {
                return webException.Message;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
            // send back the session id that should be passed to subsequent calls 
            // to webservices 
            return SessionID;
        }

        public static String Logoff(String logoffUrlString, string SessionID)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(logoffUrlString);          
            // set the session id in header
            req.Headers["JSESSIONID"] = SessionID;
            // make the HTTP call
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            return resp.StatusCode.ToString();

        }
    }

 

Hope it helps !

Bye..

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

4 thoughts on “Sample code for Inserting a lead record from a .NET application : Oracle CRM On Demand”

  1. How to retrieve value from CRM loookup field and bind it to dropdown of a custom pase to show the value on custom page

    Like

  2. Use query expression to retrieve id and name of all the records of custom entity and then bind it to the dropdown. Is it the same problem sharing and autonumbering ?

    Like

  3. Could you please share code for deleting a attachment from Admin -> Content Management -> Manage Attachment.

    I need it urgently.

    Many thanks in advance.

    Like

Leave a Reply to Nishant Rana Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

CRM for You and Me

Customer Relationship Mgt App for the Professional

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Knowhere365

Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

Two Bite Tips

Valuable Tips To Grow Your Business

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM

EVOLVED365

Step into the world of a Dynamics 365 Consultant

Dianamics PCF Lady

Diana & Dynamics 365 & Power Platform

Sara Lagerquist

No Code Customization Concepts

innovativeaj

developer, designer, writer, fun loving, patriotic, humble and a sweet person inside out :) love and respect people who have a great sense of humor.

Temmy Wahyu Raharjo

Dreaming to be a clean coder and TDD minded programmer.

Transform 365

We blog about problems we face and code we write to help others

%d bloggers like this: