Rizwan Shaikh
Rizwan Shaikh

Reputation: 95

Call Salesforce API to Add Leads using ASP.net

I am trying to call Salesforce Parnter wsdl to Create Leads to their system through my c# code.

but its giving me error: Cannot implicitly convert type Contact[]' to 'sforce.sObject'

private string userID = "[email protected]";
private string password = "sadwdasdasdasdsadasdsxzdddw";
private DateTime _nextLoginTime;
private string _sessionId;
string url="valueleads.in/pushleads/websvc/cigna/wsdl.xml";
SforceService binding;
private void getSessionInfo()
            {
                sforce.SforceService partnerService = new sforce.SforceService();
                sforce.LoginResult lr = new sforce.LoginResult();

                lr = partnerService.login(userID, password);
                _sessionId = lr.sessionId;
                Session["_sessionId"] = lr.sessionId;
                Session["_serverUrl"] = lr.serverUrl;
                Session["_nextLoginTime"] = DateTime.Now;
                binding.SessionHeaderValue = new sforce.SessionHeader();
                binding.SessionHeaderValue.sessionId = _sessionId;
                binding.Url = lr.serverUrl;
            }

            public bool IsConnected()
            {
                bool blnResult = false;
                if (!string.IsNullOrEmpty(_sessionId) & _sessionId != null)
                {
                    if (DateTime.Now > _nextLoginTime)
                        blnResult = false;
                    else
                        blnResult = true;
                }
                else
                    blnResult = false;

                return blnResult;
            }  


            public void create()
            {
               if (!IsConnected())
               {
                   getSessionInfo();
               }

                binding = new SforceService();
                Contact contact=new Contact();
                contact.fname="Eric";
                contact.lname="Peter";
                contact.mobile="9898989889";

                Contact[] contacts = { contact };
                string result;
                sforce.SaveResult[] createResults = binding.create(new sObject[] { contacts });
                if (createResults[0].success)
                {
                    result = createResults[0].id;
                }
                else
                {
                    result = createResults[0].errors[0].message;
                }
                Response.Write(result);
            }
        }

        public class Contact
        {
            public String fname { get; set; }
            public String lname { get; set; }
            public String mobile { get; set; }
        }

        }

please help, very much new to this salesforce API.

Upvotes: 1

Views: 445

Answers (1)

superfell
superfell

Reputation: 19040

You need to create an array of SObjects, not contacts, so do

sforce.sObject[] contacts = { contact };
string result;
sforce.SaveResult[] createResults = binding.create(contacts);

Upvotes: 1

Related Questions