function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gee76Gee76 

Need C# sample code to insert data into Custom Objects

Hi,

 

I'm new to Salesforce. I'm trying to insert data from my website code into Salesforce.

 

Can I get C sharp sample code to insert into Custom objects?

 

Thanks in advance

SuperfellSuperfell

foo_c f = new foo__c();

f.name = "bar";

SaveResult sr = binding.create(new SObject [] {f})[0];

 

 

Gee76Gee76

Thank you Simon. Can I also get C sharp sample code for

 

1. Updating a custom object using salesforce Id

2. Upserting a cusom object using salesforce Id

 

Thanks,

Geet

SuperfellSuperfell
Set the Id value, call update or upsert instead. See the docs.
Naveed AnwarNaveed Anwar

Im trying to upsert record using C# 

i created a class foo__c with one field as Name String type

 

binding.upsert("Name", new sObject {foo_c} ) [0];

but it's giving me error ("Cannot implicitly convert type 'foo__c' to 'apex.sObject'  )

 

 

 

SuperfellSuperfell

foo__c in the previous sample was generated from the enterprise WSDL, from a custom object called foo.

Naveed AnwarNaveed Anwar

Hey Simon Thanks for reply,

 

i am little confused here, i am new to Salesforce. let me explain you little more about my problem.

 

I am using Enterprise WSDL (i think this is generic for all .net users?) in my developer account i have custom object named "Level". i want to perform upsert, create etc operations on.

 

as u mentioned in your reply that foo was a custom object how we can access it through WSDL because WSDL not showing it in intellisense . 

 

Thanks,

Naveed 

SuperfellSuperfell

After you've created the custom object in Salesforce.com, download a new copy of the enterprise WSDL, and update your project with it. (Checkout the getting started guide in the API docs)

Naveed AnwarNaveed Anwar

:smileyhappy: Thanks Simon, Its working 

get back to you if something goes wrong in future ... 

CRM-CrackerCRM-Cracker

Hi Friends,

 

Please find the small code which may help you to insert the data into salesforce objects using c# and WSDL APIs. I stuck to much to write code in c#. I assigned using direct index after spiting you can use your ways.

 

I split the column using | (pipe sign). You may change this and also <br> , \n etc......(row and column breaking)

 

Means you can enter N rows which are in your HTML/text file. I wrote the program to add order by my designers who put the order on other website and fetch the data from e-commerce website and who has no interface for the salesforce to add/view the order records. I created one object for the same. and add following columns in the object.

 

Your suggestions are welcome.

 

Thanks

Mahendra Singh

Infogain Corporation Inc.

 

private SforceService binding;                    // declare the salesforce servive using your access credential

try
                {
                    string stroppid = "111111111111111111";
                    System.Net.HttpWebRequest fr;
                    Uri targetUri = new Uri("http://abc.xyz.com/test.html");
                    fr = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(targetUri);
                    if ((fr.GetResponse().ContentLength > 0))
                    {

                        System.IO.StreamReader str = new System.IO.StreamReader(fr.GetResponse().GetResponseStream());
                        string allrow = str.ReadToEnd();
                        string  stringSeparators = "<br>";
           
                        string[] row1 = Regex.Split(allrow, stringSeparators);
                        CDI_Order_Data__c[] cord = new CDI_Order_Data__c[row1.Length - 1];

                        for (int i = 1; i < row1.Length-1; i++)
                        {
                            string colstr = row1[i].ToString();
                            string[] allcols = Regex.Split(colstr, "\\|");

                                cord[i] = new CDI_Order_Data__c(); // Very important to create object
                                cord[i].Opportunity_Job_Order__c = stroppid;
                                cord[i].jobid__c = stroppid;
                                cord[i].order__c = allcols[0].ToString();
                                cord[i].firstname__c = allcols[1].ToString();
                                cord[i].name__c = allcols[2].ToString();
                                DateTime dtDate = Convert.ToDateTime(allcols[3]);
                                cord[i].Date__c = new DateTime(Convert.ToInt32(dtDate.Year), Convert.ToInt32(dtDate.Month), Convert.ToInt32(dtDate.Day), 0, 0, 0); //sforcedate(allcols[3]); //XMLstringToDate(allcols[3]);
                                cord[i].clientpo__c = allcols[4].ToString();
                                cord[i].billaddr1__c = allcols[5].ToString();
                                cord[i].billaddr2__c = allcols[6].ToString(); 
                                cord[i].billcity__c = allcols[7].ToString(); 
                                cord[i].billstate__c = allcols[8].ToString(); 
                                cord[i].billzip__c = allcols[9].ToString();
                                cord[i].phone__c = allcols[10].ToString(); 
                                cord[i].fax__c = allcols[11].ToString();
                                cord[i].email__c = allcols[12].ToString(); 
                                cord[i].contact__c = allcols[13].ToString(); 
                                cord[i].lastname__c = allcols[15].ToString(); 
                                cord[i].Rep__c = allcols[16].ToString(); 
                                cord[i].sidemark__c = allcols[17].ToString(); 
                                cord[i].account__c = allcols[18].ToString(); 
                                cord[i].item__c = allcols[19].ToString(); 
                                cord[i].kmatid__c = allcols[20].ToString(); 
                                cord[i].qty__c = Convert.ToDouble(allcols[21]);
                                cord[i].Description__c = allcols[22].ToString();
                                cord[i].price__c = Convert.ToDouble(allcols[23]);
                                cord[i].installation__c = allcols[24].ToString(); 
                                cord[i].freight__c = allcols[25].ToString();
                                cord[i].discount__c = Convert.ToDouble(allcols[26]);
                                cord[i].salestax__c = Convert.ToDouble(allcols[27]);
                                cord[i].taxcode__c = allcols[28].ToString();
                        }
                        try {
                            SaveResult[] saveResults = binding.create(cord);
                           
                      }
                      catch (Exception ce)
                      {
                            Response.Write("Buld order update errror" +ce.Message.ToString());
                            Response.End();
                      }

                       if (str != null) str.Close();
                   }