public void createSample() { try { // Create a new sObject of type Contact // and fill out its fields. sObject contact = new SFAccess.sObject(); System.Xml.XmlElement[] contactFields = new System.Xml.XmlElement[6]; // Create the contact's fields System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); contactFields[0] = doc.CreateElement("FirstName"); contactFields[0].InnerText = "Otto"; contactFields[1] = doc.CreateElement("LastName"); contactFields[1].InnerText = "Jespersen"; contactFields[2] = doc.CreateElement("Salutation"); contactFields[2].InnerText = "Professor"; contactFields[3] = doc.CreateElement("Phone"); contactFields[3].InnerText = "(999) 555-1234"; contactFields[4] = doc.CreateElement("Title"); contactFields[4].InnerText = "Philologist"; contact.type = "Contact"; contact.Any = contactFields; // Add this sObject to an array sObject[] contactList = new sObject[1]; contactList[0] = contact; // Make a create call and pass it the array of sObjects SaveResult[] results = binding.create(contactList); // Iterate through the results list // and write the ID of the new sObject // or the errors if the object creation failed. // In this case, we only have one result // since we created one contact. for (int j = 0; j < results.Length; j++) { if (results[j].success) { Console.Write("\nA contact was created with an ID of: " + results[j].id); } else { // There were errors during the create call, // go through the errors array and write // them to the console for (int i = 0; i < results[j].errors.Length; i++) { Error err = results[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); } } } } catch (SoapException e) { Console.WriteLine("An unexpected error has occurred: " + e.Message + " Stack trace: " + e.StackTrace); } }
public string createCTA(string name, string comments, CUser user, out ArrayList messages, out bool success) { if (user.Company == null) { throw new Exception("Can't create a CTA without a company and an Integration"); } if (user.Company.Intgr == null) { throw new Exception("Can't create a CTA without a company and an Integration"); } if (user.Company.Intgr.GainsightCTAStatus == null) { throw new Exception("Can't create a CTA without a Gainsight Info setup!"); } if (user == null || user.ExternalSystemId == null) { throw new Exception("Can't create a CTA without a salesforce Account Id on the User record!"); } Integrations integrations = user.Company.Intgr; //set up returns success = false; messages = new ArrayList(); //the id to return string idcreated = ""; //first login if (!login(out messages)) { success = false; //throw new Exception("Could not login to Salesforce"); } try { // Create a new sObject of type Contact // and fill out its fields. sObject CTA = new SFAccess.sObject(); System.Xml.XmlElement[] CTAFields = new System.Xml.XmlElement[12]; // Create the ticket's fields System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); CTAFields[0] = doc.CreateElement("JBCXM__Account__c"); CTAFields[0].InnerText = user.ExternalSystemId; CTAFields[1] = doc.CreateElement("JBCXM__Assignee__c"); CTAFields[1].InnerText = integrations.GainsightCTAUserId;// "00541000001LJxYAAW"; //------------------------------------me CTAFields[2] = doc.CreateElement("JBCXM__DueDate__c"); CTAFields[2].InnerText = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"); CTAFields[3] = doc.CreateElement("JBCXM__Priority__c"); //Alert Severity CTAFields[3].InnerText = integrations.GainsightCTAPriority; // "a0D41000001qZtYEAU"; //-------------------------------------high priority CTAFields[4] = doc.CreateElement("JBCXM__Stage__c"); //Alert STatus CTAFields[4].InnerText = integrations.GainsightCTAStatus; // "a0D41000001qZsCEAU";//---------------- stands for Open - this is like a status CTAFields[5] = doc.CreateElement("JBCXM__Type__c"); CTAFields[5].InnerText = integrations.GainsightCTAType; // "a1141000000cVEcAAM";//--------------------------------------what is type id ; CTAFields[7] = doc.CreateElement("JBCXM__Reason__c"); CTAFields[7].InnerText = integrations.GainsightCTAReason; // "a0D41000001qZsIEAU"; CTAFields[8] = doc.CreateElement("JBCXM__Comments__c"); CTAFields[8].InnerText = comments; //-------------------------------------- CTAFields[9] = doc.CreateElement("Name"); CTAFields[9].InnerText = name; CTAFields[10] = doc.CreateElement("JBCXM__CreatedDate__c"); CTAFields[10].InnerText = DateTime.Now.ToString("yyyy-MM-dd"); CTAFields[11] = doc.CreateElement("JBCXM__Playbook__c"); CTAFields[11].InnerText = integrations.GainsightCTAPlaybook;// "a0d41000000inGeAAI"; //field to set picklist Category other //JBCXM__Priority__c Alert Severity //JBCXM__Stage__c Alert Status //JBCXM__Reason__c Alert Reason //JBCXM__TypeName__c ? different object - type of CTA? event or trial //JBCXM__Account__c from account object //JBCXM__Assignee__c this is from a user //JBCXM__DueDate__c user input //JBCXM__Comments__c user input CTA.type = "JBCXM__CTA__c"; CTA.Any = CTAFields; // Add this sObject to an array sObject[] CTAList = new sObject[1]; CTAList[0] = CTA; // Make a create call and pass it the array of sObjects SaveResult[] results = binding.create(CTAList); // Iterate through the results list // and write the ID of the new sObject // or the errors if the object creation failed. // In this case, we only have one result // since we created one ticket. for (int j = 0; j < results.Length; j++) { if (results[j].success) { messages.Add("\nA CTA was created with an ID of: " + results[j].id); idcreated = results[j].id; } else { // There were errors during the create call, // go through the errors array and write // them to the console for (int i = 0; i < results[j].errors.Length; i++) { Error err = results[j].errors[i]; messages.Add("Errors were found on item " + j.ToString()); messages.Add("Error code is: " + err.statusCode.ToString()); messages.Add("Error message: " + err.message); } } } } catch (SoapException e) { messages.Add("An unexpected error has occurred: " + e.Message + " Stack trace: " + e.StackTrace); } //now logout logout(); return(idcreated); }
private string createCase(string Subject, string Description, string SuppliedCompany, string SuppliedEmail, string SuppliedName, string SuppliedPhone, string accountId, out ArrayList messages, out bool success) { string idcreated = ""; messages = new ArrayList(); success = false; //first login if (!login(out messages)) { return(""); } int hasAcctId = 0; if (!String.IsNullOrEmpty(accountId)) { hasAcctId = 1; } //Subject Description SuppliedCompany SuppliedEmail SuppliedName SuppliedPhone Status Origin try { // Create a new sObject of type Contact // and fill out its fields. sObject ticket = new SFAccess.sObject(); System.Xml.XmlElement[] ticketFields = new System.Xml.XmlElement[7 + hasAcctId]; // Create the ticket's fields System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); ticketFields[0] = doc.CreateElement("Subject"); ticketFields[0].InnerText = Subject; ticketFields[1] = doc.CreateElement("Description"); ticketFields[1].InnerText = Description; ticketFields[2] = doc.CreateElement("SuppliedCompany"); ticketFields[2].InnerText = SuppliedCompany; ticketFields[3] = doc.CreateElement("SuppliedEmail"); ticketFields[3].InnerText = SuppliedEmail; ticketFields[4] = doc.CreateElement("SuppliedName"); ticketFields[4].InnerText = SuppliedName; ticketFields[5] = doc.CreateElement("SuppliedPhone"); ticketFields[5].InnerText = SuppliedPhone; ticketFields[6] = doc.CreateElement("Origin"); ticketFields[6].InnerText = "Web"; //if we have an account id, add it to the mix to assign it to an account if (hasAcctId == 1) { ticketFields[7] = doc.CreateElement("AccountId"); ticketFields[7].InnerText = accountId; } ticket.type = "Case"; ticket.Any = ticketFields; // Add this sObject to an array sObject[] ticketList = new sObject[1]; ticketList[0] = ticket; // Make a create call and pass it the array of sObjects SaveResult[] results = binding.create(ticketList); // Iterate through the results list // and write the ID of the new sObject // or the errors if the object creation failed. // In this case, we only have one result // since we created one ticket. for (int j = 0; j < results.Length; j++) { if (results[j].success) { messages.Add("A ticket was created with an ID of: " + results[j].id); idcreated = results[j].id; success = true; } else { // There were errors during the create call, // go through the errors array and write // them to the console for (int i = 0; i < results[j].errors.Length; i++) { Error err = results[j].errors[i]; messages.Add("Errors were found on item " + j.ToString()); messages.Add("Error code is: " + err.statusCode.ToString()); messages.Add("Error message: " + err.message); } } } } catch (SoapException e) { messages.Add("An unexpected error has occurred: " + e.Message); messages.Add("Stack trace: " + e.StackTrace); } //now logout logout(); return(idcreated); }
public string createCTA(string Subject, string Description, CUser user) { //to use in the CTA object for Gainsight /*JBCXM__Account__c, * JBCXM__Assignee__c, * JBCXM__DueDate__c, * JBCXM__Priority__c, * JBCXM__Reason__c, * JBCXM__Stage__c, * JBCXM__Type__c, = 'a3SG000000073q9MAA' * JBCXM__TypeName__c, * */ //the id to return string idcreated = ""; //first login if (!login()) { throw new Exception("Could not login to Salesforce"); } try { // Create a new sObject of type Contact // and fill out its fields. sObject CTA = new SFAccess.sObject(); System.Xml.XmlElement[] CTAFields = new System.Xml.XmlElement[8]; // Create the ticket's fields System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); CTAFields[0] = doc.CreateElement("JBCXM__Account__c"); CTAFields[0].InnerText = user.ExternalSystemId; CTAFields[1] = doc.CreateElement("JBCXM__Assignee__c"); CTAFields[1].InnerText = "pkumar"; //------------------------------------what is this one? id CTAFields[2] = doc.CreateElement("JBCXM__DueDate__c"); CTAFields[2].InnerText = DateTime.Now.ToString(); CTAFields[3] = doc.CreateElement("JBCXM__Priority__c"); //Alert Severity CTAFields[3].InnerText = "a3SG00000005SJQMA2"; //-------------------------------------high priority CTAFields[4] = doc.CreateElement("JBCXM__Stage__c"); //Alert STatus CTAFields[4].InnerText = "a3SG000000073q9MAA"; //---------------- stands for Open - this is like a status // CTAFields[5] = doc.CreateElement("JBCXM__Type__c"); //CTAFields[5].InnerText = "a5UG0000000GoSUMA0";//--------------------------------------what is type id ; CTAFields[6] = doc.CreateElement("JBCXM__TypeName__c"); CTAFields[6].InnerText = "Event"; //--------------------------------------Event //field to set picklist Category other //JBCXM__Priority__c Alert Severity //JBCXM__Stage__c Alert Status //JBCXM__Reason__c Alert Reason //JBCXM__TypeName__c ? different object - type of CTA? event or trial //JBCXM__Account__c from account object //JBCXM__Assignee__c this is from a user //JBCXM__DueDate__c user input //JBCXM__Comments__c user input CTA.type = "JBCXM__CTA__c"; CTA.Any = CTAFields; // Add this sObject to an array sObject[] CTAList = new sObject[1]; CTAList[0] = CTA; // Make a create call and pass it the array of sObjects SaveResult[] results = binding.create(CTAList); // Iterate through the results list // and write the ID of the new sObject // or the errors if the object creation failed. // In this case, we only have one result // since we created one ticket. for (int j = 0; j < results.Length; j++) { if (results[j].success) { Console.Write("\nA CTA was created with an ID of: " + results[j].id); idcreated = results[j].id; } else { // There were errors during the create call, // go through the errors array and write // them to the console for (int i = 0; i < results[j].errors.Length; i++) { Error err = results[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); } } } } catch (SoapException e) { Console.WriteLine("An unexpected error has occurred: " + e.Message + " Stack trace: " + e.StackTrace); } //now logout logout(); return(idcreated); }