コード例 #1
0
        private String createAndDeleteAnAccount(String accountName)
        {
            String returnId = null;
            sObject acct = new sObject();
            acct.type = "Account";
            acct.Any = new System.Xml.XmlElement[] { GetNewXmlElement("Name", (accountName == null) ? "QueryAll Sample" : accountName) };
            try
            {
                //We are only creating one account so we can index the return array directly
                SaveResult sr = binding.create(new sObject[] { acct })[0];
                if (sr.success)
                {

                    acct.Id = sr.id;
                    //Ok, now we will delete that account
                    DeleteResult dr = binding.delete(new String[] { acct.Id })[0];
                    if (!dr.success)
                    {
                        Console.WriteLine("The web service would not let us delete the account: \n" + dr.errors[0].message + "\nHit return to continue...");
                        Console.ReadLine();
                    }
                    else
                    {
                        returnId = acct.Id;
                    }

                }
                else
                {
                    Console.WriteLine("The web service would not let us create the account: \n" + sr.errors[0].message + "\nHit return to continue...");
                    Console.ReadLine();
                }
            }
            catch (System.Web.Services.Protocols.SoapException e)
            {
                Console.WriteLine("Error creating test account: " + e.Message + "\nHit return to continue...");
                Console.ReadLine();
            }
            return returnId;
        }
コード例 #2
0
        private void createContactSample()
        {
            //Verify that we are already authenticated, if not
            //call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                    return;
            }

            try
            {

                sObject[] cons = new sObject[1];
                apex.sObject contact;
                for (int j = 0; j < cons.Length; j++)
                {
                    contact = new apex.sObject();
                    int index = 0;
                    System.Xml.XmlElement[] cont = new System.Xml.XmlElement[17];
                    if (accounts != null)
                    {
                        cont = new System.Xml.XmlElement[cont.Length + 1];
                        cont[index++] = GetNewXmlElement("AccountId", accounts[0]);
                    }
                    cont[index++] = GetNewXmlElement("AssistantName", "Jane");
                    cont[index++] = GetNewXmlElement("AssistantPhone", "777.777.7777");
                    cont[index++] = GetNewXmlElement("Department", "Purchasing");
                    cont[index++] = GetNewXmlElement("Description", "International IT Purchaser");
                    cont[index++] = GetNewXmlElement("Email", "*****@*****.**");
                    cont[index++] = GetNewXmlElement("Fax", "555.555.5555");
                    cont[index++] = GetNewXmlElement("MailingCity", "San Mateo");
                    cont[index++] = GetNewXmlElement("MailingCountry", "US");
                    cont[index++] = GetNewXmlElement("MailingState", "CA");
                    cont[index++] = GetNewXmlElement("MailingStreet", "1129 B Street");
                    cont[index++] = GetNewXmlElement("MailingPostalCode", "94105");
                    cont[index++] = GetNewXmlElement("MobilePhone", "888.888.8888");
                    cont[index++] = GetNewXmlElement("FirstName", "Joe");
                    cont[index++] = GetNewXmlElement("LastName", "Blow");
                    cont[index++] = GetNewXmlElement("Salutation", "Mr.");
                    cont[index++] = GetNewXmlElement("Phone", "999.999.9999");
                    cont[index++] = GetNewXmlElement("Title", "Purchasing Director");
                    contact.Any = cont;
                    contact.type = "Contact";
                    cons[j] = contact;
                }
                SaveResult[] sr = binding.create(cons);
                for (int j = 0; j < sr.Length; j++)
                {
                    if (sr[j].success)
                    {
                        Console.WriteLine("A contact was create with an id of: "
                            + sr[j].id);
                        if (accounts != null)
                            Console.WriteLine(" - the contact was associated with the account you created with an id of "
                                + accounts[0]
                                + ".");

                        if (contacts == null)
                        {
                            contacts = new string[] { sr[j].id };
                        }
                        else
                        {
                            string[] tempContacts = null;
                            tempContacts = new string[contacts.Length + 1];
                            for (int i = 0; i < contacts.Length; i++)
                                tempContacts[i] = contacts[i];
                            tempContacts[contacts.Length] = sr[j].id;
                            contacts = tempContacts;
                        }
                    }
                    else
                    {
                        //there were errors during the create call, go through the errors
                        //array and write them to the screen
                        for (int i = 0; i < sr[j].errors.Length; i++)
                        {
                            //get the next error
                            Error err = sr[j].errors[i];
                            Console.WriteLine("Errors were found on item " + j.ToString());
                            Console.WriteLine("Error code is: " + err.statusCode.ToString());
                            Console.WriteLine("Error message: " + err.message);
                        }
                    }
                    Console.Write("\nHit return to continue...");
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nFailed to execute query succesfully, error message was: \n"
                    + ex.Message);
                Console.Write("\nHit return to continue...");
                Console.ReadLine();
            }
        }
コード例 #3
0
        private void updateAccountSample()
        {
            //Verify that we are already authenticated, if not
            //call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                    return;
            }

            try
            {
                //check to see if there are any accounts created in this session
                if (accounts == null)
                {
                    Console.WriteLine("\nUpdate operation not completed.  You will need to create an account during this session to run the update sample.");
                    Console.Write("\nHit return to continue...");
                    Console.ReadLine();
                    return;
                }

                //create the account object to hold our changes
                apex.sObject updateAccount = new apex.sObject();
                //need to have the id so that web service knows which account to update
                updateAccount.Id = accounts[0];
                //set a new value for the name property
                updateAccount.Any = new System.Xml.XmlElement[] { this.GetNewXmlElement("Name", "New Account Name from Update Sample") };
                updateAccount.type = "Account";

                //create one that will throw an error
                apex.sObject errorAccount = new apex.sObject();
                errorAccount.Id = "S:DLFKJLFKJ";
                errorAccount.Any = new System.Xml.XmlElement[] { this.GetNewXmlElement("Name", "Error") };
                errorAccount.fieldsToNull = new string[] { "Name" };
                errorAccount.type = "Account";

                //call the update passing an array of object
                SaveResult[] saveResults = binding.update(new apex.sObject[] { updateAccount, errorAccount });

                //loop through the results, checking for errors
                for (int j = 0; j < saveResults.Length; j++)
                {
                    Console.WriteLine("Item: " + j);
                    if (saveResults[j].success)
                        Console.WriteLine("An account with an id of: " + saveResults[j].id + " was updated.\n");
                    else
                    {
                        Console.WriteLine("Item " + j.ToString() + " had an error updating.");
                        Console.WriteLine("    The error reported was: " + saveResults[j].errors[0].message + "\n");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nFailed to succesfully update an account, error message was: \n"
                           + ex.Message);
            }
            Console.WriteLine("\nHit return to continue...");
            Console.ReadLine();
        }
コード例 #4
0
        private void upsertSample()
        {
            // TODO Auto-generated method stub
            // Verify that we are already authenticated, if not
            // call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                {
                    return;
                }
            }

            try
            {

                DescribeSObjectResult dsr = binding.describeSObject("Account");
                System.Collections.Hashtable fieldMap = this.makeFieldMap(dsr.fields);
                if (!fieldMap.ContainsKey("External_Id__c"))
                {
                    Console.WriteLine("\n\nNOTICE: To run the upsert sample you need \nto add a custom field named \nExternal_Id to the account object.  \nSet the size of the field to 8 characters \nand be sure to check the 'External Id' checkbox.");
                } else {
                    //First, we need to make sure the test accounts do not exist.
                    QueryResult qr = binding.query("Select Id From Account Where External_Id__c = '11111111' or External_Id__c = '22222222'");
                    if (qr.size > 0)
                    {
                        sObject[] accounts = (sObject[])qr.records;
                        //Get the ids
                        String[] ids = new String[accounts.Length];
                        for (int i = 0; i < ids.Length; i++)
                        {
                            ids[i] = accounts[i].Id;
                        }
                        //Delete the accounts
                        binding.delete(ids);
                    }

                    //Create a new account using create, we wil use this to update via upsert
                    //We will set the external id to be ones so that we can use that value for the upsert
                    sObject newAccount = new sObject();
                    newAccount.type = "Account";
                    newAccount.Any = new System.Xml.XmlElement[] { GetNewXmlElement("Name", "Account to update"),
                        GetNewXmlElement("External_Id__c", "11111111") };
                    binding.create(new sObject[] { newAccount });

                    //Now we will create an account that should be updated on insert based
                    //on the external id field.
                    sObject updateAccount = new sObject();
                    updateAccount.type = "Account";
                    updateAccount.Any = new System.Xml.XmlElement[] { GetNewXmlElement("Website", "http://www.website.com"),
                        GetNewXmlElement("External_Id__c", "11111111") };

                    // This account is meant to be new
                    sObject createAccount = new sObject();
                    createAccount.type = "Account";
                    createAccount.Any = new System.Xml.XmlElement[] { GetNewXmlElement("Name", "My Company, Inc"),
                        GetNewXmlElement("External_Id__c", "22222222") };

                    //We have our two accounts, one should be new, the other should be updated.
                    try
                    {
                        // Invoke the upsert call and save the results.
                        // Use External_Id custom field for matching records
                        UpsertResult[] upsertResults = binding.upsert("External_Id__c", new sObject[] { createAccount, updateAccount });
                        for (int i = 0; i < upsertResults.Length; i++)
                        {
                            UpsertResult result = upsertResults[i];
                            if (result.success)
                            {
                                Console.WriteLine("\nUpsert succeeded.");
                                Console.WriteLine((result.created ? "Inserted" : "Updated") + " account, id is " + result.id);
                            }
                            else
                            {
                                Console.WriteLine("The Upsert failed because: " + result.errors[0].message);
                            }
                        }
                    }
                    catch (System.Web.Services.Protocols.SoapException ex)
                    {
                        Console.WriteLine("Error from web service: " + ex.Message);
                    }
                }
                Console.WriteLine("\nPress the RETURN key to continue...");
                Console.ReadLine();
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                Console.WriteLine("Error merging account: " + ex.Message + "\nHit return to continue...");
                Console.ReadLine();
            }
        }
コード例 #5
0
        private void processSample()
        {
            // Verify that we are already authenticated, if not
            // call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                {
                    return;
                }
            }

            try
            {
                //First step is to create an account that matches the approval process criteria
                sObject acct = new sObject();
                acct.type = "Account";
                acct.Any = new System.Xml.XmlElement[] { GetNewXmlElement("Name", "API Approval Sample") };
                acct.Id = binding.create(new sObject[] { acct })[0].id;

                // Next step is to submit the account for approval using a ProcessSubmitRequest
                ProcessSubmitRequest psr = new ProcessSubmitRequest();
                psr.objectId = acct.Id;
                psr.comments = "This approval request was initiated from the API.";
                ProcessResult p_res = binding.process(new ProcessRequest[] { psr })[0];
                if (p_res.success)
                {
                    //Since the submission was successful we can now approve or reject it with
                    // a ProcessWorkItmeRequest
                    ProcessWorkitemRequest pwr = new ProcessWorkitemRequest();
                    pwr.action = "Approve";
                    pwr.comments = "This request was approved from the API.";
                    pwr.workitemId = p_res.newWorkitemIds[0];
                    p_res = binding.process(new ProcessRequest[] { pwr })[0];
                    if (p_res.success)
                    {
                        Console.WriteLine("Successfully submitted and then approved an approval request.");
                    }
                    else
                    {
                        Console.WriteLine("Error approving the work item: " + p_res.errors[0].message);
                    }
                }
                else
                {
                    Console.WriteLine("Error submitting the account for approval: " + p_res.errors[0].message);
                }
            }
            catch (System.Web.Services.Protocols.SoapException e)
            {
                Console.WriteLine("The API returned a fault: " + e.Message);
            }
            Console.WriteLine("\nHit the enter key to continue...");
            Console.ReadLine();
        }
コード例 #6
0
        private void createAccountSample()
        {
            //Verify that we are already authenticated, if not
            //call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                    return;
            }

            try
            {
                apex.sObject account;
                sObject[] accs = new sObject[2];
                for (int j = 0; j < accs.Length; j++)
                {
                    account = new apex.sObject();
                    System.Xml.XmlElement[] acct = new System.Xml.XmlElement[14];
                    int index = 0;
                    if (accounts == null)
                        acct[index++] = GetNewXmlElement("AccountNumber", "0000000");
                    else
                        acct[index++] = GetNewXmlElement("AccountNumber", "000000" + (accounts.Length + 1));
                    //account.setAnnualRevenue(new java.lang.Double(4000000.0));
                    acct[index++] = GetNewXmlElement("BillingCity", "Wichita");
                    acct[index++] = GetNewXmlElement("BillingCountry", "US");
                    acct[index++] = GetNewXmlElement("BillingState", "KA");
                    acct[index++] = GetNewXmlElement("BillingStreet", "4322 Haystack Boulevard");
                    acct[index++] = GetNewXmlElement("BillingPostalCode", "87901");
                    acct[index++] = GetNewXmlElement("Description", "World class hay makers.");
                    acct[index++] = GetNewXmlElement("Fax", "555.555.5555");
                    acct[index++] = GetNewXmlElement("Industry", "Farming");
                    acct[index++] = GetNewXmlElement("Name", "Golden Straw");
                    acct[index++] = GetNewXmlElement("NumberOfEmployees", "40");
                    acct[index++] = GetNewXmlElement("Ownership", "Privately Held");
                    acct[index++] = GetNewXmlElement("Phone", "666.666.6666");
                    acct[index++] = GetNewXmlElement("Website", "www.oz.com");
                    account.type = "Account";
                    account.Any = acct;
                    accs[j] = account;
                }

                //create the object(s) by sending the array to the web service
                SaveResult[] sr = binding.create(accs);
                for (int j = 0; j < sr.Length; j++)
                {
                    if (sr[j].success)
                    {
                        Console.Write(System.Environment.NewLine + "An account was create with an id of: "
                            + sr[j].id);

                        //save the account ids in a class array
                        if (accounts == null)
                        {
                            accounts = new string[] { sr[j].id };
                        }
                        else
                        {
                            string[] tempAccounts = null;
                            tempAccounts = new string[accounts.Length + 1];
                            for (int i = 0; i < accounts.Length; i++)
                                tempAccounts[i] = accounts[i];
                            tempAccounts[accounts.Length] = sr[j].id;
                            accounts = tempAccounts;
                        }
                    }
                    else
                    {
                        //there were errors during the create call, go through the errors
                        //array and write them to the screen
                        for (int i = 0; i < sr[j].errors.Length; i++)
                        {
                            //get the next error
                            Error err = sr[j].errors[i];
                            Console.WriteLine("Errors were found on item " + j.ToString());
                            Console.WriteLine("Error code is: " + err.statusCode.ToString());
                            Console.WriteLine("Error message: " + err.message);
                        }
                    }
                }
                Console.WriteLine("\nHit return to continue...");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nFailed to create account, error message was: \n"
                           + ex.Message);
                Console.Write("\nHit return to continue...");
                Console.ReadLine();
            }
        }
コード例 #7
0
        private void emptyRecycleBinSample()
        {
            //Verify that we are already authenticated, if not
            //call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                    return;
            }

            try
            {
                Console.Write("\nEmpty the recycle bin? (Y/N) ");
                String response = Console.ReadLine();
                if (response.ToLower().Equals("y"))
                {
                    // We will create some accounts and then delete them and use
                    // the ids for the emptyRecycleBin method.
                    sObject[] accounts = new sObject[10];
                    for (int i = 0; i < accounts.Length; i++)
                    {
                        accounts[i] = new sObject();
                        accounts[i].Any = new System.Xml.XmlElement[1];
                        accounts[i].Any[0] = GetNewXmlElement("Name", "Test account " + i);
                        accounts[i].type = "Account";
                    }
                    // save the new accounts
                    String[] createdItemIds = new String[10];
                    SaveResult[] sr = binding.create(accounts);
                    for (int i = 0; i < sr.Length; i++)
                    {
                        if (sr[i].success)
                        {
                            createdItemIds[i] = sr[i].id;
                        }
                    }
                    // now, delete them
                    DeleteResult[] dr = binding.delete(createdItemIds);
                    String[] deletedItemIds = new String[sr.Length];
                    for (int i = 0; i < dr.Length; i++)
                    {
                        if (dr[i].success)
                        {
                            deletedItemIds[i] = dr[i].id;
                        }
                    }

                    //call the emptyRecycleBin method
                    EmptyRecycleBinResult[] results = binding.emptyRecycleBin(deletedItemIds);

                    for (int i = 0; i < results.Length; i++)
                    {
                        if (results[i].success)
                        {
                            Console.WriteLine("Lead with id: " + results[i].id + " was successfully queued for permanant delete.");
                        }
                        else
                        {
                            Console.WriteLine("A problem occurred queueing item with id: " + results[i].id + " for permanent delete.");
                        }
                    }
                    Console.WriteLine("Empty recycle bin finished.");
                    Console.ReadLine();
                }
            }
            catch (Exception ex3)
            {
                Console.WriteLine("ERROR: emptying recycle bin.\n" + ex3.Message);
            }
        }
コード例 #8
0
 /// <remarks/>
 public System.IAsyncResult Beginupdate(sObject[] sObjects, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("update", new object[] {
                 sObjects}, callback, asyncState);
 }
コード例 #9
0
 /// <remarks/>
 public void upsertAsync(string externalIDFieldName, sObject[] sObjects) {
     this.upsertAsync(externalIDFieldName, sObjects, null);
 }
コード例 #10
0
 /// <remarks/>
 public void upsertAsync(string externalIDFieldName, sObject[] sObjects, object userState) {
     if ((this.upsertOperationCompleted == null)) {
         this.upsertOperationCompleted = new System.Threading.SendOrPostCallback(this.OnupsertOperationCompleted);
     }
     this.InvokeAsync("upsert", new object[] {
                 externalIDFieldName,
                 sObjects}, this.upsertOperationCompleted, userState);
 }
コード例 #11
0
 /// <remarks/>
 public System.IAsyncResult Beginupsert(string externalIDFieldName, sObject[] sObjects, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("upsert", new object[] {
                 externalIDFieldName,
                 sObjects}, callback, asyncState);
 }
コード例 #12
0
 /// <remarks/>
 public void updateAsync(sObject[] sObjects, object userState) {
     if ((this.updateOperationCompleted == null)) {
         this.updateOperationCompleted = new System.Threading.SendOrPostCallback(this.OnupdateOperationCompleted);
     }
     this.InvokeAsync("update", new object[] {
                 sObjects}, this.updateOperationCompleted, userState);
 }
コード例 #13
0
 /// <remarks/>
 public void updateAsync(sObject[] sObjects) {
     this.updateAsync(sObjects, null);
 }
コード例 #14
0
        private void createLeadSample()
        {
            //Verify that we are already authenticated, if not
            //call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                    return;
            }

            try
            {

                sObject[] leads = new sObject[1];
                apex.sObject lead;
                lead = new apex.sObject();
                int index = 0;
                System.Xml.XmlElement[] leadEls = new System.Xml.XmlElement[17];
                leadEls[index++] = GetNewXmlElement("AnnualRevenue", System.Xml.XmlConvert.ToString(1000000.0));
                leadEls[index++] = GetNewXmlElement("AnnualRevenueSpecified", System.Xml.XmlConvert.ToString(true));
                leadEls[index++] = GetNewXmlElement("City", "San Francisco");
                leadEls[index++] = GetNewXmlElement("Company", "Acme Anvils");
                leadEls[index++] = GetNewXmlElement("Country", "United States");
                leadEls[index++] = GetNewXmlElement("CurrencyIsoCode", "USD");
                leadEls[index++] = GetNewXmlElement("Description", "This is a lead that can be converted.");
                leadEls[index++] = GetNewXmlElement("DoNotCall", System.Xml.XmlConvert.ToString(false));
                leadEls[index++] = GetNewXmlElement("DoNotCallSpecified", System.Xml.XmlConvert.ToString(true));
                Console.Write("\nPlease enter an email for the lead we are creating.");
                string email = Console.ReadLine();
                if (email == null)
                    leadEls[index++] = GetNewXmlElement("Email", "*****@*****.**");
                else
                    leadEls[index++] = GetNewXmlElement("Email", email);
                leadEls[index++] = GetNewXmlElement("Fax", "5555555555");
                leadEls[index++] = GetNewXmlElement("FirstName", "Wiley");
                leadEls[index++] = GetNewXmlElement("HasOptedOutOfEmail", System.Xml.XmlConvert.ToString(false));
                leadEls[index++] = GetNewXmlElement("HasOptedOutOfEmailSpecified", System.Xml.XmlConvert.ToString(true));
                leadEls[index++] = GetNewXmlElement("Industry", "Blacksmithery");
                leadEls[index++] = GetNewXmlElement("LastName", "Coyote");
                leadEls[index++] = GetNewXmlElement("LeadSource", "Web");
                leadEls[index++] = GetNewXmlElement("MobilePhone", "4444444444");
                leadEls[index++] = GetNewXmlElement("NumberOfEmployees", System.Xml.XmlConvert.ToString(30));
                leadEls[index++] = GetNewXmlElement("NumberOfEmployeesSpecified", System.Xml.XmlConvert.ToString(true));
                leadEls[index++] = GetNewXmlElement("NumberofLocations__c", System.Xml.XmlConvert.ToString(1.0));
                leadEls[index++] = GetNewXmlElement("NumberofLocations__cSpecified", System.Xml.XmlConvert.ToString(true));
                leadEls[index++] = GetNewXmlElement("Phone", "6666666666");
                leadEls[index++] = GetNewXmlElement("PostalCode", "94105");
                leadEls[index++] = GetNewXmlElement("Rating", "Hot");
                leadEls[index++] = GetNewXmlElement("Salutation", "Mr.");
                leadEls[index++] = GetNewXmlElement("State", "California");
                leadEls[index++] = GetNewXmlElement("Status", "Working");
                leadEls[index++] = GetNewXmlElement("Street", "10 Downing Street");
                leadEls[index++] = GetNewXmlElement("Title", "Director of Directors");
                leadEls[index++] = GetNewXmlElement("Website", "www.acmeanvils.com");

                lead.Any = leadEls;
                lead.type = "Lead";
                leads[0] = lead;

                SaveResult[] sr = binding.create(leads);
                for (int j = 0; j < sr.Length; j++)
                {
                    if (sr[j].success)
                    {
                        Console.WriteLine("A lead was create with an id of: "
                            + sr[j].id);
                    }
                    else
                    {
                        //there were errors during the create call, go through the errors
                        //array and write them to the screen
                        for (int i = 0; i < sr[j].errors.Length; i++)
                        {
                            //get the next error
                            Error err = sr[j].errors[i];
                            Console.WriteLine("Errors were found on item " + j.ToString());
                            Console.WriteLine("Error code is: " + err.statusCode.ToString());
                            Console.WriteLine("Error message: " + err.message);
                        }
                    }
                    Console.Write("\nHit return to continue...");
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nFailed to execute query succesfully, error message was: \n"
                    + ex.Message);
                Console.Write("\nHit return to continue...");
                Console.ReadLine();
            }
        }
コード例 #15
0
        private void mergeSample()
        {
            // TODO Auto-generated method stub
            // Verify that we are already authenticated, if not
            // call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                {
                    return;
                }
            }

            try
            {
                sObject masterAccount = new sObject();
                masterAccount.type = "Account";
                masterAccount.Any = new System.Xml.XmlElement[] { GetNewXmlElement("Name", "MasterAccount") };
                SaveResult masterAccountSaveResult;
                masterAccountSaveResult = binding.create(new sObject[] { masterAccount })[0];
                masterAccount.Id = masterAccountSaveResult.id;
                System.Xml.XmlElement[] masterAny = masterAccount.Any;
                System.Array.Resize(ref masterAny, (masterAccount.Any.Length + 1));
                masterAny[masterAny.Length - 1] = GetNewXmlElement("Description", "Old description");
                masterAccount.Any = masterAny;

                sObject accountToMerge = new sObject();
                accountToMerge.type = "Account";
                accountToMerge.Any = new System.Xml.XmlElement[] { GetNewXmlElement("Name", "AccountToMerge"),
                    GetNewXmlElement("Description", "Duplicate account") };

                SaveResult accountToMergeSaveResult = binding.create(new sObject[] { accountToMerge })[0];

                //Attach a note, which will get re-parented
                sObject note = new sObject();
                note.type = "Note";
                note.Any = new System.Xml.XmlElement[] { GetNewXmlElement("ParentId", accountToMergeSaveResult.id),
                    GetNewXmlElement("Body", "This note will be moved to the MasterAccount during merge"),
                    GetNewXmlElement("Title", "Test note to be reparented.") };

                SaveResult noteSave = binding.create(new sObject[] { note })[0];

                MergeRequest mr = new MergeRequest();

                //Perform an update on the master record as part of the merge:
                masterAccount.Any[masterAccount.Any.Length - 1] = GetNewXmlElement("Description", "Was merged");

                mr.masterRecord = masterAccount;
                mr.recordToMergeIds = (new String[] { accountToMergeSaveResult.id });
                MergeResult result = binding.merge(new MergeRequest[] { mr })[0];

                Console.WriteLine("Merged " + result.success + " got " +
                result.updatedRelatedIds.Length + " updated child records\nHit return to continue.");
                Console.ReadLine();

            }
            catch (System.Web.Services.Protocols.SoapException e)
            {
                Console.WriteLine("Error merging account: " + e.Message + "\nHit return to continue...");
                Console.ReadLine();
            }
        }
コード例 #16
0
        private void createTaskSample()
        {
            //Verify that we are already authenticated, if not
            //call the login function to do so
            if (!loggedIn)
            {
                if (!login())
                    return;
            }

            try
            {
                //create an array to create 4 items in one call
                sObject[] taskarray = new sObject[3];
                for (int x = 0; x < taskarray.Length; x++)
                {
                    //Declare a new task object to hold our values
                    apex.sObject task = new apex.sObject();
                    int index = 0;
                    System.Xml.XmlElement[] tsk = new System.Xml.XmlElement[5];
                    if (contacts != null) tsk = new System.Xml.XmlElement[tsk.Length + 1];
                    if (accounts != null) tsk = new System.Xml.XmlElement[tsk.Length + 1];
                    //make sure we get some errors on records 3 and 4
                    if (x > 1)
                    {
                        tsk = new System.Xml.XmlElement[tsk.Length + 1];
                        tsk[index++] = GetNewXmlElement("OwnerId", "DSF:LJKSDFLKJ");
                    }

                    //Set the appropriate values on the task
                    tsk[index++] = GetNewXmlElement("ActivityDate", GetDateTimeSerialized(DateTime.Now));
                    tsk[index++] = GetNewXmlElement("Description", "Get in touch with this person");
                    tsk[index++] = GetNewXmlElement("Priority", "Normal");
                    tsk[index++] = GetNewXmlElement("Status", "Not Started");
                    tsk[index++] = GetNewXmlElement("Subject", "Setup Call");
                    //The two lines below illustrate associating an object with another object.  If
                    //we have created an account and/or a contact prior to creating the task, we will
                    //just grab the first account and/or contact id and place it in the appropriate
                    //reference field.  WhoId can be a reference to a contact or a lead or a user.
                    //WhatId can be a reference to an account, campaign, case, contract or opportunity
                    if (contacts != null) tsk[index++] = GetNewXmlElement("WhoId", contacts[0]);
                    if (accounts != null) tsk[index++] = GetNewXmlElement("WhatId", accounts[0]);
                    task.type = "Task";
                    taskarray[x] = task;
                }

                //call the create method passing the array of tasks as sobjects
                SaveResult[] sr = binding.create(taskarray);

                for (int j = 0; j < sr.Length; j++)
                {
                    if (sr[j].success)
                    {
                        Console.WriteLine("A task was create with an id of: "
                            + sr[j].id);
                        if (accounts != null)
                            Console.WriteLine(" - the task was associated with the account you created with an id of "
                                + accounts[0]
                                + ".");

                        if (tasks == null)
                        {
                            tasks = new string[] { sr[j].id };
                        }
                        else
                        {
                            string[] tempTasks = null;
                            tempTasks = new string[tasks.Length + 1];
                            for (int i = 0; i < tasks.Length; i++)
                                tempTasks[i] = tasks[i];
                            tempTasks[tasks.Length] = sr[j].id;
                            tasks = tempTasks;
                        }

                    }
                    else
                    {
                        //there were errors during the create call, go through the errors
                        //array and write them to the screen
                        for (int i = 0; i < sr[j].errors.Length; i++)
                        {
                            //get the next error
                            Error err = sr[j].errors[i];
                            Console.WriteLine("Errors were found on item " + j.ToString());
                            Console.WriteLine("Error code is: " + err.statusCode.ToString());
                            Console.WriteLine("Error message: " + err.message);
                        }
                    }
                    Console.WriteLine("\nCreate task successful.");
                }
                Console.Write("\nHit return to continue...");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nFailed to succesfully create a task, error message was: \n"
                    + ex.Message);
                Console.Write("\nHit return to continue...");
                Console.ReadLine();
            }
        }
コード例 #17
0
 /// <remarks/>
 public void createAsync(sObject[] sObjects) {
     this.createAsync(sObjects, null);
 }