public DataReturn RunSOQL(string soqlQuery) { //todo - add page handling //for now get everything DataReturn dr = new DataReturn(); DataTable dt = dr.dt; try { QueryResult qr = _binding.query(soqlQuery); bool done = false; bool first = true; if (qr.size > 0) { while (!done) { sObject[] records = qr.records; for (int i = 0; i < qr.records.Length; i++) { if (first) { //Build the datatable for (int j = 0; j < records[i].Any.Length; j++) { AddColumn(dt, records[i].Any[j],""); } first = false; } DataRow rw = dt.NewRow(); for (int j = 0; j < records[i].Any.Length; j++) { AddData(rw, records[i].Any[j],""); } dt.Rows.Add(rw); } if (qr.done) { done = true; } else { qr = _binding.queryMore(qr.queryLocator); } } } else { //Still need to create the table so have the template when creating a new one //just create string fields for each of the select fields - don't mind the amatuer hour parsing! string temp = soqlQuery.Trim(); temp = temp.Substring("select".Length, temp.Length - "select".Length); temp = temp.Substring(0, temp.IndexOf(" from ",StringComparison.CurrentCultureIgnoreCase)); temp = temp.Trim(); string[] fieldnames = temp.Split(','); foreach (string f in fieldnames) { dt.Columns.Add(new DataColumn(f.Replace(".","_").Trim(), typeof(String))); } } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } if (dt.Columns.Contains("Id")) dt.PrimaryKey = new DataColumn[] {dt.Columns["Id"]}; return dr; }
public DataReturn RunSOQL(SForceEdit.SObjectDef sObj) { DataReturn dr = new DataReturn(); //Build Query string soqlQuery = "select " + sObj.GetQueryList() + " from " + sObj.Name + ""; //See if there is a fitler string filter = ""; string filterdefaultsort = ""; // see if we have defined filters if (sObj.GridFilters.Count > 0) { // defined filters // get the userid - check if there is an error, this could be the first thing to be called after a timeout string userid = ""; try { userid = GetUserId(); } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; return dr; } if (sObj.Filter!=null && sObj.GridFilters.ContainsKey(sObj.Filter)) { AxiomIRISRibbon.SForceEdit.SObjectDef.FilterEntry f = sObj.GridFilters[sObj.Filter]; string soql = f.SOQL; soql = soql.Replace("{UserId}", userid); if(soql!="") filter = " where " + soql; filterdefaultsort = f.OrderBy==""?"":" ORDER BY " + f.OrderBy; } } if (sObj.Search != "") { filter += (filter == "" ? " where " : " and "); filter += sObj.GetSearchClause(); } if (sObj.Parent != "") { filter += (filter == "" ? " where " : " and "); string pclause = sObj.Parent; if (!pclause.EndsWith("__c")) { pclause += "Id"; } // if the parent id is blank we really want none - this is when we create a new parent and the // subtab is selected - can't just be parent='' cause there maybe children that have no parent and SOQL // returns them if you do ='' - so make it a dummy Id instead if (sObj.ParentId == "") { filter += pclause + " = '123456789012345678'"; } else { filter += pclause + " = '" + sObj.ParentId + "'"; } } if (sObj.Id != "") { filter += (filter == "" ? " where " : " and "); filter += "Id = '" + sObj.Id + "'"; } soqlQuery += filter; if (sObj.Paging) { if (sObj.SortColumn != "") { soqlQuery += " ORDER BY " + sObj.SortQueryField + " " + sObj.SortDir; } else { soqlQuery += filterdefaultsort; } soqlQuery += " LIMIT " + sObj.RecordsPerPage.ToString() + " OFFSET " + (sObj.CurrnetPage * sObj.RecordsPerPage).ToString(); try { //Get total count QueryResult qr = _binding.query("select count() from " + sObj.Name + filter); Globals.Ribbons.Ribbon1.SFDebug("GetCount>" + sObj.Name, "select count() from " + sObj.Name + filter); sObj.TotalRecords = qr.size; } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; return dr; } } else { if (sObj.SortColumn == null || sObj.SortColumn == "") { soqlQuery += filterdefaultsort; } } //Create the DataTable from the Definition dr.dt = sObj.CreateDataTable(); try { QueryResult qr = _binding.query(soqlQuery); Globals.Ribbons.Ribbon1.SFDebug("Get>" + sObj.Name, soqlQuery); bool done = false; if (qr.size > 0) { while (!done) { sObject[] records = qr.records; for (int i = 0; i < qr.records.Length; i++) { DataRow rw = dr.dt.NewRow(); for (int j = 0; j < records[i].Any.Length; j++) { AddData(sObj, rw, records[i].Any[j], ""); } dr.dt.Rows.Add(rw); } if (qr.done) { done = true; } else { qr = _binding.queryMore(qr.queryLocator); Globals.Ribbons.Ribbon1.SFDebug("GetMore>" + sObj.Name, "More>" + soqlQuery); } } } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } return dr; }
//New PES public DataReturn CloneAttachmentFile(string ParentId, string AttachmentName, string Xml) { DataReturn dr = new DataReturn(); string id = ""; String soqlQuery = "SELECT Id FROM Attachment where ParentId='" + ParentId + "' and Name='" + AttachmentName + "' order by LastModifiedDate desc limit 1"; try { QueryResult qr = _binding.query(soqlQuery); if (qr.size > 0) { sObject[] records = qr.records; for (int i = 0; i < qr.records.Length; i++) { id = records[i].Any[0].InnerText; } } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } sObject attach = new sObject(); attach.type = "Attachment"; System.Xml.XmlElement[] o; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); SaveResult[] sr; if (id == "") { // Create the attacchments fields o = new System.Xml.XmlElement[4]; doc = new System.Xml.XmlDocument(); o[0] = doc.CreateElement("Name"); o[0].InnerText = AttachmentName; o[1] = doc.CreateElement("isPrivate"); o[1].InnerText = "false"; o[2] = doc.CreateElement("ParentId"); o[2].InnerText = ParentId; o[3] = doc.CreateElement("Body"); byte[] data = Convert.FromBase64String(Xml); o[3].InnerText = Convert.ToBase64String(data); attach.Any = o; sr = _binding.create(new sObject[] { attach }); for (int j = 0; j < sr.Length; j++) { if (sr[j].success) { id = sr[j].id; } else { for (int i = 0; i < sr[j].errors.Length; i++) { dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i]; } } } } else { // Update the attacchments fields doc = new System.Xml.XmlDocument(); o = new System.Xml.XmlElement[1]; o[0] = doc.CreateElement("Body"); // o[0].InnerText = Convert.ToBase64String(System.Text.Encoding.Unicode.GetBytes(Xml)); byte[] data = Convert.FromBase64String(Xml); o[0].InnerText = Convert.ToBase64String(data); attach.Any = o; attach.Id = id; sr = _binding.update(new sObject[] { attach }); for (int j = 0; j < sr.Length; j++) { if (sr[j].success) { id = sr[j].id; } else { for (int i = 0; i < sr[j].errors.Length; i++) { dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i]; } } } } dr.id = id; return dr; }
public DataReturn LoadDefinitions(string[] sObjects) { DataReturn dr = new DataReturn(); _allSObjects = new Dictionary<string, DescribeGlobalSObjectResult>(); _describeSObject = new Dictionary<string, DescribeSObjectResult>(); _describeSearch = new Dictionary<string, DescribeSearchLayoutResult>(); _describeLayout = new Dictionary<string, DescribeLayoutResult>(); try { //First get the Global List of objects DescribeGlobalResult dgr = _binding.describeGlobal(); Globals.Ribbons.Ribbon1.SFDebug("Global Describe"); DescribeGlobalSObjectResult[] sObjResults = dgr.sobjects; for (int i = 0; i < sObjResults.Length; i++) { _allSObjects.Add(sObjResults[i].name, sObjResults[i]); } //Check the defined objects exist List<string> sObjectsExist = new List<string>(); for (int i = 0; i < sObjects.Length; i++) { if(_allSObjects.ContainsKey(sObjects[i])) sObjectsExist.Add(sObjects[i]); } sObjects = sObjectsExist.ToArray(); DescribeSObjectResult[] dso = _binding.describeSObjects(sObjects); Globals.Ribbons.Ribbon1.SFDebug("Describe Objects"+ string.Join("|",sObjects)); for (int i = 0; i < dso.Length; i++) { _describeSObject.Add(sObjects[i], dso[i]); } /* this doesn't actually get what we need! it gives what the search returns in SForce when you do a generic accross object saerch wnated to get the ListView but can only get using MetaData and have to be admin - so using config for now // Think this is for search pages - remove Task, it doesn't have a search layout string[] sObjectsWithoutTasks = sObjects.Where(val => val != "Task").ToArray(); DescribeSearchLayoutResult[] dslr = _binding.describeSearchLayouts(sObjectsWithoutTasks); Globals.Ribbons.Ribbon1.SFDebug("Describe Layouts" + string.Join("|", sObjectsWithoutTasks)); for (int i = 0; i < dslr.Length; i++) { _describeSearch.Add(sObjectsWithoutTasks[i], dslr[i]); } */ for (int i = 0; i < sObjects.Length; i++) { //Attachment doesn't have a layout if (sObjects[i] != "Attachment") { _describeLayout.Add(sObjects[i], _binding.describeLayout(sObjects[i], null,null)); Globals.Ribbons.Ribbon1.SFDebug("Describe Layouts for " + sObjects[i]); } } } catch (Exception e) { dr.success = false; dr.errormessage = e.Message; } return dr; }
public DataReturn GetPickListValues(string sObject,string fName) { DataReturn dr = new DataReturn(); DataTable dt = dr.dt; System.Data.DataColumn c = new DataColumn("Value", typeof(String)); dt.Columns.Add(c); try { DescribeSObjectResult[] dsrArray = _binding.describeSObjects(new string[] { sObject }); DescribeSObjectResult dsr = dsrArray[0]; for (int i = 0; i < dsr.fields.Length; i++) { Field field = dsr.fields[i]; if (field.name == fName) { if (field.type.Equals(fieldType.picklist)) { for (int j = 0; j < field.picklistValues.Length; j++) { DataRow rw = dt.NewRow(); rw["Value"] = field.picklistValues[j].value; dt.Rows.Add(rw); } } } } } catch(Exception e){ dr.success = false; dr.errormessage = e.Message; } return dr; }
// get the specified static file as a string public DataReturn GetStaticResource(string name) { DataReturn dr = new DataReturn(); byte[] b; string base64 = ""; dr.strRtn = ""; String soqlQuery = "SELECT Id,Body FROM StaticResource where Name='" + name + "'"; try { QueryResult qr = _binding.query(soqlQuery); Globals.Ribbons.Ribbon1.SFDebug("Get Settings File", soqlQuery); if (qr.size > 0) { sObject[] records = qr.records; for (int i = 0; i < qr.records.Length; i++) { base64 = records[i].Any[1].InnerText; } } //Convert to string if (base64 != "") { b = Convert.FromBase64String(base64); dr.strRtn = Encoding.UTF8.GetString(b); } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } return dr; }
public DataReturn GetAttachment(string Id, string AttachmentName) { DataReturn dr = new DataReturn(); String soqlQuery = "SELECT Body FROM Attachment where ParentId='" + Id + "' and Name='" + AttachmentName + "' order by LastModifiedDate desc limit 1"; try { QueryResult qr = _binding.query(soqlQuery); Globals.Ribbons.Ribbon1.SFDebug("Get Attachment", soqlQuery); if (qr.size > 0) { sObject[] records = qr.records; for (int i = 0; i < qr.records.Length; i++) { dr.strRtn = records[i].Any[0].InnerText; } } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } if (dr.strRtn != "") { dr.strRtn = System.Text.Encoding.Unicode.GetString(Convert.FromBase64String(dr.strRtn)); } return dr; }
public DataReturn getLatestVersionDetails(string matterId) { // DataReturn matterRecordDataReturn=new DataReturn(); string latestVersionId; //string LatestVersionDetail; // LatestVersionDetail = "SELECT Id FROM version__c WHERE matter__c = '" + matterId + "' and version_number__c != null order by version_number__c desc limit 1"; DataReturn latestVersionDataReturn = _sf.RunSOQL("SELECT Id FROM version__c WHERE matter__c = '" + matterId + "' and version_number__c != null order by version_number__c desc limit 1"); // DataTable latestVersionDataTable = latestVersionDataReturn.dt; if (latestVersionDataReturn.dt.Rows.Count > 0) { latestVersionId = latestVersionDataReturn.dt.Rows[0][0].ToString(); matterRecordDataReturn = _sf.RunSOQL("SELECT parentid FROM attachment WHERE parentid = '" + latestVersionId + "'"); } else { matterRecordDataReturn.errormessage = "Cloning cannot occur since selected Agreement does not have an available Version."; } return matterRecordDataReturn; }
public DataReturn UpdateAttachmentFile(string Id,string AttachmentName,string FileName) { DataReturn dr = new DataReturn(); byte[] b; try { b = System.IO.File.ReadAllBytes(FileName); } catch (Exception e) { dr.errormessage = e.Message; dr.success = false; return dr; } sObject attach = new sObject(); attach.type = "Attachment"; System.Xml.XmlElement[] o; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); SaveResult[] sr; // Update the attacchments fields doc = new System.Xml.XmlDocument(); o = new System.Xml.XmlElement[AttachmentName==""?1:2]; o[0] = doc.CreateElement("Body"); o[0].InnerText = Convert.ToBase64String(b); if (AttachmentName != "") { o[1] = doc.CreateElement("Name"); o[1].InnerText = AttachmentName; } attach.Any = o; attach.Id = Id; try { sr = _binding.update(new sObject[] { attach }); Globals.Ribbons.Ribbon1.SFDebug("Update Attachment"); for (int j = 0; j < sr.Length; j++) { if (sr[j].success) { Id = sr[j].id; } else { for (int i = 0; i < sr[j].errors.Length; i++) { dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i]; } } } } catch (Exception e) { dr.errormessage = e.Message; dr.success = false; return dr; } dr.id = Id; return dr; }
public DataReturn ExecRibbonCall(string Action,string Obj,string Id) { DataReturn dr = new DataReturn(); sfRibbon.RibbonRequest req = new RibbonRequest(); req.action = Action; req.objname = Obj; req.id = Id; try { sfRibbon.RibbonResponse res = _ribbonBinding.Dispatch(req); Globals.Ribbons.Ribbon1.SFDebug("Call Axiom_RibbonCntroller", "Action:" + Action + " Obj:" + Obj + " Id:" + Id); dr.success = (res.success == null ? false : (res.success == true ? true : false)); dr.id = res.selectid; dr.reload = res.reload; dr.strRtn = res.message; } catch (Exception ex) { dr.success = false; dr.strRtn = ex.Message; } return dr; }
public DataReturn Delete(string sObjectName, string id) { DataReturn dr = new DataReturn(); DeleteResult[] drslt = _binding.delete(new string[]{id}); Globals.Ribbons.Ribbon1.SFDebug("Delete", "Delete:" + id); for (int j = 0; j < drslt.Length; j++) { DeleteResult deleteResult = drslt[j]; if (deleteResult.success) { dr.id = deleteResult.id; } else { Error[] errors = deleteResult.errors; for (int k = 0; k < errors.Length; k++) { dr.errormessage += (dr.errormessage == "" ? "" : ",") + errors[k]; } } } return dr; }
//Given a DataRow, update or Create the SalesForce Object //Assuming that we have just one row, easy to change to handle multiples public DataReturn Save(SForceEdit.SObjectDef sObj, DataRow dRow) { DataReturn dr = new DataReturn(); sObject s = new sObject(); s.type = sObj.Name; string id = ""; if (dRow["Id"] == null || dRow["Id"].ToString() == "") { //new int fldCount = dRow.Table.Columns.Count - 1; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); System.Xml.XmlElement[] o = new System.Xml.XmlElement[fldCount]; fldCount = 0; List<string> fieldsToNull = new List<string>(); foreach (DataColumn dc in dRow.Table.Columns) { //Get the field definition SForceEdit.SObjectDef.FieldGridCol f = sObj.GetField(dc.ColumnName); // this is a new record so do it even if it says its readonly but exclud any _Name or _Type if (!f.Create) { //nada ... } else if (dc.ColumnName == "Id") { //Nothing! } else if (dc.ColumnName == "type") { //don't do anything - this happens when we have the type field from a join } else { object val = dRow[dc.ColumnName]; if (dRow[dc.ColumnName] == DBNull.Value) { fieldsToNull.Add(dc.ColumnName); } else { o[fldCount] = doc.CreateElement(dc.ColumnName); string sval = ""; if (f.DataType == "datetime") { sval = ((DateTime)val).ToString("o"); } else if (f.DataType == "date") { sval = ((DateTime)val).ToString("yyyy-MM-dd"); } else { sval = CleanUpXML(val.ToString()); } o[fldCount].InnerText = sval; fldCount++; } } } try { // dont need to set the values to Null! this is a create so just don't tell them // s.fieldsToNull = fieldsToNull.ToArray(); s.Any = Utility.SubArray<System.Xml.XmlElement>(o, 0, fldCount); sfPartner.SaveResult[] sr = _binding.create(new sObject[] { s }); Globals.Ribbons.Ribbon1.SFDebug("Save>" + s.type); for (int j = 0; j < sr.Length; j++) { if (sr[j].success) { dr.id = sr[j].id; } else { dr.success = false; for (int i = 0; i < sr[j].errors.Length; i++) { dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i].message; } } } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } } else { //update int fldCount = dRow.Table.Columns.Count; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); System.Xml.XmlElement[] o = new System.Xml.XmlElement[fldCount]; fldCount = 0; List<string> fieldsToNull = new List<string>(); foreach (DataColumn dc in dRow.Table.Columns) { //Get the field definition SForceEdit.SObjectDef.FieldGridCol f = sObj.GetField(dc.ColumnName); if (dc.ColumnName == "Id") { s.Id = dRow[dc.ColumnName].ToString(); } else if (!f.Update) { //not on the list ... } else if (dc.ColumnName == "type") { //don't do anything - this happens when we have the type field from a join } else { object val = dRow[dc.ColumnName]; if (dRow[dc.ColumnName] == DBNull.Value || ((f.DataType != "string") && dRow[dc.ColumnName].ToString() == "")) { fieldsToNull.Add(dc.ColumnName); } else { o[fldCount] = doc.CreateElement(dc.ColumnName); string sval = ""; if (f.DataType == "datetime") { sval = ((DateTime)val).ToString("o"); } else if (f.DataType == "date") { sval = ((DateTime)val).ToString("yyyy-MM-dd"); } else { sval = CleanUpXML(val.ToString()); } o[fldCount].InnerText = sval; fldCount++; } } } try { s.fieldsToNull = fieldsToNull.ToArray(); s.Any = Utility.SubArray<System.Xml.XmlElement>(o, 0, fldCount); sfPartner.SaveResult[] sr = _binding.update(new sObject[] { s }); Globals.Ribbons.Ribbon1.SFDebug("Update>" + s.type); for (int j = 0; j < sr.Length; j++) { Console.WriteLine("\nItem: " + j); if (sr[j].success) { dr.id = sr[j].id; } else { dr.success = false; for (int i = 0; i < sr[j].errors.Length; i++) { dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i].message; } } } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } } return dr; }
private void btnInsert_Click(object sender, RoutedEventArgs e) { if (Globals.ThisAddIn.isTemplate()) { Globals.ThisAddIn.ProcessingStart("Insert Clause"); //save - exit if we don't get an id back string clauseid = tbId.Text; if (btnSave.IsEnabled) { Globals.ThisAddIn.ProcessingUpdate("Save Clause"); clauseid = Save(); if (clauseid == "") { return; } } string conceptid = ((ComboBoxItem)cbConcept.SelectedItem).Tag.ToString(); string templateclauseid = ""; //if this is an Insert then we will have the templateid if (_templateid != "") { Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument; if (_templateclausemode == "clone") { // if we are cloning then we know that the control is there and we just have to save the link and update the tree Globals.ThisAddIn.ProcessingUpdate("Add the Clause to the Template"); DataReturn dr = new DataReturn(); // Check if it is already there - this can happen if the control is removed // from the document or if they try and add the clause twice dr = Utility.HandleData(_d.GetTemplateClause(_templateid, clauseid)); if (dr.dt.Rows.Count == 0) { string name = Utility.Truncate(_templatename, 35) + "-" + Utility.Truncate(tbName.Text, 35); dr = Utility.HandleData(_d.SaveTemplateClause("", name, _templateid, clauseid, "","")); if (!dr.success) return; templateclauseid = dr.id; } else { templateclauseid = dr.dt.Rows[0]["Id"].ToString(); } } else { // First things first - see if we can insert teh content control - if we can't then don't do anything else // and flag it as a problem Globals.ThisAddIn.ProcessingUpdate("Check the selection"); Word.Selection sel = Globals.ThisAddIn.Application.Selection; Word.ContentControl c; try { // ok we get an error if there is a pagebreak followed directly by the section we are trying to add // so add a paragraph sel.Range.InsertBefore("\r"); c = sel.Document.ContentControls.Add(Word.WdContentControlType.wdContentControlRichText); } catch (Exception ex) { // get rid of the return we just inserted try { if (sel.Range.Start > 0) doc.Range(sel.Range.Start - 1, sel.Range.Start).Delete(); } catch (Exception ex2) { } Globals.ThisAddIn.ProcessingUpdate("Cannot create a clause holder in the current selection"); Globals.ThisAddIn.ProcessingStop("End"); MessageBox.Show("Sorry, can't create a clause holder with the current selection! :" + ex.Message); return; } // get rid of the return we just inserted - does somehting odd when its the first letter if (sel.Range.Start > 0) doc.Range(sel.Range.Start - 1, sel.Range.Start).Delete(); //Add to Contract Template Globals.ThisAddIn.ProcessingUpdate("Add the Clause to the Template"); DataReturn dr = new DataReturn(); // Check if it is already there - this can happen if the control is removed // from the document or if they try and add the clause twice dr = Utility.HandleData(_d.GetTemplateClause(_templateid, clauseid)); if (dr.dt.Rows.Count == 0) { string name = Utility.Truncate(_templatename, 35) + "-" + Utility.Truncate(tbName.Text, 35); dr = Utility.HandleData(_d.SaveTemplateClause("", name, _templateid, clauseid, "","")); if (!dr.success) return; templateclauseid = dr.id; } else { templateclauseid = dr.dt.Rows[0]["Id"].ToString(); } //Check we don't already have this concept in the template - we just added one so make sure we don't have 2 Globals.ThisAddIn.ProcessingUpdate("Check if we have this concept"); if (Utility.HandleData(_d.GetTemplateClauseCount(_templateid, conceptid)).dt.Rows.Count > 1) { if (_templateclausemode == "inplace") { //Just remove the selection - it is now incorporated in the concept Globals.ThisAddIn.ProcessingUpdate("Remove Selection"); sel.Delete(); try { c.Delete(); } catch (Exception) { } } } else { // Add in the new concept // fix can only be 64 chars! c.Title = Utility.Truncate(cbConcept.Text,64); c.Tag = "Concept|" + conceptid.ToString(); c.LockContentControl = true; c.LockContents = true; } } //Save! important to try and keep things in sync try { doc.Save(); } catch (Exception) { } } // Update the list bars - This reloads everything from Salesforce for all open templates // so too **slow** - only update mentions of *this* clause // Globals.ThisAddIn.ProcessingStop("Refresh All Open Contracts"); // Globals.ThisAddIn.RefreshAllTaskPanes(); // For now just relaod this one // this is also too slow! // need to just do this **CLAUSE** // update the concept list as we may have created a new one Globals.ThisAddIn.GetTaskPaneControlTemplate().RefreshConceptList(); Globals.ThisAddIn.ProcessingUpdate("Refresh Tree"); Globals.ThisAddIn.GetTaskPaneControlTemplate().RefreshClause(clauseid,templateclauseid); this.Hide(); Globals.ThisAddIn.ProcessingStop("Done"); } }
//Given a DataRow, update or Create the SalesForce Object //Assuming that we have just one row, easy to change to handle multiples public DataReturn Save(string sObjectName, DataRow dRow) { DataReturn dr = new DataReturn(); sObject s = new sObject(); s.type = sObjectName; string id = ""; List<string> fieldsToNull = new List<string>(); if (dRow["Id"] == null || dRow["Id"].ToString() == "") { //new int fldCount = dRow.Table.Columns.Count - 1; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); System.Xml.XmlElement[] o = new System.Xml.XmlElement[fldCount]; fldCount = 0; foreach (DataColumn dc in dRow.Table.Columns) { if (dc.ColumnName == "Id") { //Nothing! } else if (dc.ColumnName == "type" || dc.ColumnName == "LastModifiedDate" || dc.ColumnName == "CreatedDate") { //don't do anything - this happens when we have the type field from a join } else { if (dc.ColumnName.Contains("__r_")) { if (dc.ColumnName.EndsWith("Id")) { string tn = dc.ColumnName; tn = tn.Substring(0, tn.IndexOf("__r_")); //Concept__r_Id becomes Concept__c tn += "__c"; o[fldCount] = doc.CreateElement(tn); o[fldCount].InnerText = CleanUpXML(dRow[dc.ColumnName].ToString()); fldCount++; } //Otherwise do nothing } else { o[fldCount] = doc.CreateElement(dc.ColumnName); o[fldCount].InnerText = CleanUpXML(dRow[dc.ColumnName].ToString()); fldCount++; } } } try { s.Any = Utility.SubArray<System.Xml.XmlElement>(o, 0, fldCount); SaveResult[] sr = _binding.create(new sObject[] { s }); for (int j = 0; j < sr.Length; j++) { if (sr[j].success) { dr.id = sr[j].id; } else { dr.success = false; for (int i = 0; i < sr[j].errors.Length; i++) { dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i].message; } } } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } } else { //update int fldCount = dRow.Table.Columns.Count; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); System.Xml.XmlElement[] o = new System.Xml.XmlElement[fldCount]; fldCount = 0; foreach (DataColumn dc in dRow.Table.Columns) { if (dc.ColumnName == "Id") { s.Id = dRow[dc.ColumnName].ToString(); } else if (dc.ColumnName == "type" || dc.ColumnName == "LastModifiedDate" || dc.ColumnName == "CreatedDate") { //don't do anything - this happens when we have the type field from a join } else { //For relations - ignore all the other fields except the _Id one //e.g. "Concept__r_Name" "Concept__r_Id" - ignore all but Id //TODO: won't work Nested! need to try this out with a realation of a relation if (dc.ColumnName.Contains("__r_")) { if (dc.ColumnName.EndsWith("Id")) { string tn = dc.ColumnName; tn = tn.Substring(0, tn.IndexOf("__r_")); //Concept__r_Id becomes Concept__c tn += "__c"; string val = CleanUpXML(dRow[dc.ColumnName].ToString()); if (val == "") { fieldsToNull.Add(dc.ColumnName); } else { o[fldCount] = doc.CreateElement(tn); o[fldCount].InnerText = val; fldCount++; } } //Otherwise do nothing } else { string val = CleanUpXML(dRow[dc.ColumnName].ToString()); if(val==""){ fieldsToNull.Add(dc.ColumnName); } else{ o[fldCount] = doc.CreateElement(dc.ColumnName); o[fldCount].InnerText = val; fldCount++; } } } } try { s.fieldsToNull = fieldsToNull.ToArray(); s.Any = Utility.SubArray<System.Xml.XmlElement>(o, 0, fldCount); SaveResult[] sr = _binding.update(new sObject[] { s }); for (int j = 0; j < sr.Length; j++) { Console.WriteLine("\nItem: " + j); if (sr[j].success) { dr.id = sr[j].id; } else { dr.success = false; for (int i = 0; i < sr[j].errors.Length; i++) { dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i].message; } } } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } } return dr; }
public DataReturn GetAttachmentFile(string Id,string filename) { DataReturn dr = new DataReturn(); byte[] b; string base64 = ""; dr.strRtn = ""; String soqlQuery = "SELECT Id,ParentId,Body FROM Attachment where Id='" + Id + "'"; try { QueryResult qr = _binding.query(soqlQuery); Globals.Ribbons.Ribbon1.SFDebug("Get Attachment", soqlQuery); if (qr.size > 0) { sObject[] records = qr.records; for (int i = 0; i < qr.records.Length; i++) { base64 = records[i].Any[2].InnerText; } } //Save as a file if (base64 != "") { b = Convert.FromBase64String(base64); System.IO.File.WriteAllBytes(filename, b); dr.strRtn = filename; } } catch (Exception ex) { dr.success = false; dr.errormessage = ex.Message; } return dr; }
public DataReturn GetPickListValues(string sObject, string fName, bool reload) { if (!reload && _cache.ContainsKey("PickList|" + sObject + "|" + fName)) { DataReturn dr = new DataReturn(); dr.dt = _cache["PickList|" + sObject + "|" + fName]; dr.success = true; dr.fromcache = true; return dr; } else { DataReturn dr = _sf.GetPickListValues(sObject, fName); if (dr.success) _cache["PickList|" + sObject + "|" + fName] = dr.dt; return dr; } }
//pavan public DataReturn SaveRibbonClause(DataTable ribbontempCause, List<string> clauseIds, string templateId) { // List<string> ribbonClauseIds = new List<string>(); int i = 0; foreach (DataRow drow in ribbontempCause.Rows) { // ribbonClauseIds.Add(drow.Table.Rows[i][2].ToString()); i++; } // DataReturn dr = new DataReturn(); //foreach (string ribbonclauseId in ribbonClauseIds) //{ // //foreach (DataRow drow in ribbontempCause.Rows) foreach (string clauseId in clauseIds) { // //if(clauseId == drow.Table.Columns[2].ToString()) //if (drow.Table.Rows[0][2].ToString().Contains(clauseId)) if (ribbonClauseIds.Contains(clauseId)) { //nothing } else { // DataRow drowNew = ribbontempCause.NewRow(); drowNew["name"] = templateId + " - " + clauseId; drowNew["clause__c"] = clauseId; drowNew["template__c"] = templateId; dr = _sf.Save("RibbonTemplateClause__c", drowNew); } } //} return dr; }