I want to get the emails of unsubscribers the code below returning the count that how many of it are there but how could i get the List of unsubscribers from output variable...
Here is my full code::
private List<campaignUnsubscribesResults.Unsubscribes> Unsubscribers = new List<campaignUnsubscribesResults.Unsubscribes>();
private void GetUnsubscribers(string apikey, string MailChimpCampaignID)
{
campaignUnsubscribesInput input = new campaignUnsubscribesInput();
input.api_AccessType = PerceptiveMCAPI.EnumValues.AccessType.Serial;
input.api_CustomErrorMessages = true;
input.api_MethodType = PerceptiveMCAPI.EnumValues.MethodType.POST;
input.api_Validate = true;
input.api_OutputType = PerceptiveMCAPI.EnumValues.OutputType.XML;
input.parms.apikey = apikey;
input.parms.cid = MailChimpCampaignID;
//input.parms.start = PageIndex;
//input.parms.limit = PageSize;
campaignUnsubscribes unsubscribe = new campaignUnsubscribes();
campaignUnsubscribesOutput output = unsubscribe.Execute(input);
Unsubscribers.AddRange(output.result.data);
string unsubscriber = "0";
//ArrayList a = new ArrayList();
//a[0] = output.result.data.ToString();
//List<MCItem> lst = new List<MCItem>();
// foreach (listBatchUnsubscribeResults order in myArrayList)
//{
// orders.add(order);
//}
string[] unsubs;
//ArrayList [] list = new ArrayList [0];
foreach (listMembers list1 in output.result)
{
unsubscriber = list1.ToString();
}
string unsubscribers = Unsubscribers.Count.ToString();
Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language=JavaScript>alert('Unsubscribers:: '+ ' " + unsubscribers + " ');</script>");
//Unsubscribers.Reverse();
//dlUnsubscribes.DataSource = Unsubscribers.Take(10);
//dlUnsubscribes.DataBind();
//dlUnsubscribes.Visible = (Unsubscribers.Count > 0);
}
I would use Mailchimp Webhooks. You setup a page/script on your website which will get called by Mailchimp every time a particular event occurs. When it's an unsubscribe event, you can log the info you want to store to a database, file, etc.
Related
DocuSign doesn't pass values back into Salesforce. And Even doesn't give me any errors in the logs.
I used a Custom Field like source ID and MergeFieldXml tab option with the write-back = true. But it doesn't work.
Please advise what is wrong?
Merge fields are enabled for the DocuSign account.
My code example:
global class AnnualContract
{
webService static string AM_SendToDocuSign(String id, string strObjType)
{
Docusign_API_Setting__c APISetting = Docusign_API_Setting__c.getInstance('API Settings');
String envelopeId = '';
string DealerName = '';
string DealerId = '';
String accountId = APISetting.AccountId__c;
String userId = APISetting.UserId__c;
String password = APISetting.Password__c;
String integratorsKey = APISetting.IntegratorsKey__c;
String webServiceUrl = APISetting.WebServiceUrl__c;
list<Lead> lstLead = new list<Lead>();
list<Contact> lstContact = new list<Contact>();
if(strObjType == 'Lead')
{
lstLead = [SELECT Name,Status,Email,FirstName,LastName,Owner.Name,Title,FROM Lead where id = : Id limit 1];
}
StaticResource objSR = [SELECT Id,name, SystemModStamp FROM StaticResource WHERE Name = 'AnnualContractPDF' LIMIT 1];
String url_file_ref = '/resource/' + String.valueOf(((DateTime)objSR.get('SystemModStamp')).getTime())+ '/' + objSR.get('Name');
if(strObjType == 'Lead')
{
DealerName = lstLead[0].Name;
}
DocuSignAPI.APIServiceSoap dsApiSend = new DocuSignAPI.APIServiceSoap();
dsApiSend.endpoint_x = webServiceUrl;
//Set Authentication
String auth = '<DocuSignCredentials><Username>'+ userId
+'</Username><Password>' + password
+ '</Password><IntegratorKey>' + integratorsKey
+ '</IntegratorKey></DocuSignCredentials>';
System.debug('Setting authentication to: ' + auth);
dsApiSend.inputHttpHeaders_x = new Map<String, String>();
dsApiSend.inputHttpHeaders_x.put('X-DocuSign-Authentication',
auth);
DocuSignAPI.Envelope envelope = new DocuSignAPI.Envelope();
envelope.Subject = 'Please Sign this Contract' + lstLead[0].Name;
envelope.EmailBlurb = 'This is my new eSignature service, it allows me to get your signoff without having to fax, scan, retype, refile and wait forever';
envelope.AccountId = accountId;
// Render the contract
System.debug('Rendering the contract');
PageReference pageRef = new PageReference(url_file_ref);
Blob pdfBlob = pageRef.getContent();
DocuSignAPI.CustomField field = new DocuSignAPI.CustomField ();
field.Name = '##SFLead';
field.Value = lstLead[0].Id; //value of the external source Id
field.Show = 'false';
field.CustomFieldType = 'Text';
envelope.CustomFields = new DocuSignAPI.ArrayOfCustomField();
envelope.CustomFields.CustomField = new DocuSignAPI.CustomField[1];
envelope.CustomFields.CustomField[0] = field;
// Document
DocuSignAPI.Document document = new DocuSignAPI.Document();
document.ID = 1;
document.pdfBytes = EncodingUtil.base64Encode(pdfBlob);
document.Name = 'Annual Contract';
document.FileExtension = 'pdf';
envelope.Documents = new DocuSignAPI.ArrayOfDocument();
envelope.Documents.Document = new DocuSignAPI.Document[1];
envelope.Documents.Document[0] = document;
// Recipient
System.debug('Building up the recipient');
DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
recipient.ID = 1;
recipient.Type_x = 'Signer';
recipient.RoutingOrder = 1;
recipient.Email = lstLead[0].Email;
recipient.UserName = lstLead[0].FirstName + ' ' + lstLead[0].LastName;
recipient.RequireIDLookup = false;
envelope.Recipients = new DocuSignAPI.ArrayOfRecipient();
envelope.Recipients.Recipient = new DocuSignAPI.Recipient[1];
envelope.Recipients.Recipient[0] = recipient;
// Tab
DocuSignAPI.Tab tab1 = new DocuSignAPI.Tab();
tab1.Type_x = 'SignHere';
tab1.RecipientID = 1;
tab1.DocumentID = 1;
tab1.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab1.AnchorTabItem.AnchorTabString = '/t1/';
tab1.AnchorTabItem.XOffset = 100;
DocuSignAPI.Tab tab2 = new DocuSignAPI.Tab();
tab2.Type_x = 'DateSigned';
tab2.RecipientID = 1;
tab2.DocumentID = 1;
tab2.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab2.AnchorTabItem.AnchorTabString = '/d1/';
DocuSignAPI.Tab tab3 = new DocuSignAPI.Tab();
tab3.CustomTabType = 'Text';
tab3.Name = 'Title';
tab3.Type_x = 'Custom';
tab3.RecipientID = 1;
tab3.DocumentID = 1;
tab3.TabLabel = 'Title';
if(strObjType == 'Lead')
{
if(lstLead[0].Title != null)
{
tab3.Value = ''+lstLead[0].Title+'';
}
}
else
{
if(lstContact[0].Title != null)
{
tab3.Value = ''+lstContact[0].Title+'';
}
}
tab3.CustomTabWidth=100;
tab3.CustomTabRequired=false;
tab3.CustomTabLocked=false;
tab3.CustomTabDisableAutoSize=false;
tab3.TemplateLocked=false;
tab3.TemplateRequired=false;
tab3.ConditionalParentLabel='';
tab3.ConditionalParentValue='';
tab3.SharedTab=true;
tab3.RequireInitialOnSharedTabChange=false;
tab3.ConcealValueOnDocument=false;
tab3.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab3.AnchorTabItem.AnchorTabString = '/t2/';
tab3.AnchorTabItem.XOffset = 42;
tab3.AnchorTabItem.YOffset = -5;
tab3.MergeFieldXml = '<mergeField><allowSenderToEdit>true</allowSenderToEdit><configurationType>salesforce</configurationType><path>Lead.Title</path><row>1</row><writeBack>true</writeBack></mergeField>';
envelope.Tabs = new DocuSignAPI.ArrayOfTab();
envelope.Tabs.Tab = new DocuSignAPI.Tab[3];
envelope.Tabs.Tab[0] = tab1;
envelope.Tabs.Tab[1] = tab2;
envelope.Tabs.Tab[2] = tab3;
System.debug('Calling the API');
try {
DocuSignAPI.EnvelopeStatus es = dsApiSend.CreateAndSendEnvelope(envelope);
envelopeId = es.EnvelopeID;
System.debug('Returned successfully, envelope id = ' + envelopeId );
return '';
} catch ( CalloutException e) {
System.debug('Exception - ' + e );
envelopeId = 'Exception - ' + e;
return '';
}
return '';
}
}
I resolved the issue with the DocuSign support.
MergeFieldXml for SOAP should be like this:
tab3.MergeFieldXml ='<mergefieldconfig configversion="1.0" service="salesforce"><mergefield><writeenabled>true</writeenabled><sendercanedit>true</sendercanedit><queryfrom><obj><type>Lead</type><name>Lead</name><field><fieldtype>string</fieldtype><name>Title</name></field></obj></queryfrom></mergefield></mergefieldconfig>';
I have a C# .net application using the rally 3.0.1 API. When I query task in my system I get 0.0 for time spent when I know they have time against them. Anyone know how to get this? Below is my code:
if (uTasks.Count > 0)
{
Request taskRequest = new Request(resultChild["Tasks"]);
QueryResult TaskQueryResult = restApi.Query(taskRequest);
foreach (var items in TaskQueryResult.Results)
//foreach (var items in uTasks)
{
DataRow dtrow2;
dtrow2 = dt.NewRow();
dtrow2["TaskID"]=items["FormattedID"];
dtrow2["Task Name"] = items["Name"];
if (items["Owner"] != null)
{
var owner = items["Owner"];
String ownerref = owner["_ref"];
var ownerFetch = restApi.GetByReference(ownerref, "Name");
string strTemp = ownerFetch["_refObjectName"];
dtrow2["Owner"] = strTemp.Replace(",", " ");
}
\\else { dtrow2["Owner"] = ""; }
dtrow2["Task-Est"] = items["Estimate"];
dtrow2["Task-ToDo"] = items["ToDo"];
dtrow2["Task-Spent"] = items["TimeSpent"];
dtrow2["ObjectType"] = "T";
dt.Rows.Add(dtrow2);
}
}
It seems like that should work. You may want to make sure you're including the TimeSpent field in your fetch before issuing the request.
taskRequest.Fetch = new List<string>() { "TimeSpent" };
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Web.Url, SPUserToken.SystemAccount))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPFolder folder = web.Folders["ContractorDetails"];
SPFileCollection filecol = folder.Files;
Boolean replaceExistingFiles = true;
string filename = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
byte[] contents = new byte[Convert.ToInt32(FileUpload.PostedFile.ContentLength)];
SPFile addedFile = filecol.Add(filename, contents, replaceExistingFiles);
SPItem newItem = addedFile.Item;
newItem["Title"] = ddlTitle.SelectedValue;
newItem["First Name"] = tbFirstName.Text;
newItem["Middle Name"] = tbMiddleName.Text;
newItem["Last Name"] = tbLastName.Text;
newItem["NT User Name"] = tbNtuser.Text;
newItem["Contract Firm"] = tbContractFirm.Text;
newItem["Employee Type"] = tbEmpType.Text;
newItem["Division"] = ddlDivision.SelectedValue;
newItem["Location"] = ddlLocation.SelectedValue;
newItem["Contract Start Date"] = dateTimeStart.SelectedDate;
newItem["Contract End Date"] = dateTimeEnd.SelectedDate;
newItem["Project Term"] = Convert.ToInt32(tbProjectTerm.Text);
// newItem["Manager"] = PeopleEditor1.t
newItem["Comments"] = tbcomments.Text;
newItem.Update();
addedFile.Update();
web.AllowUnsafeUpdates = false;
}
}
});
}
Can you just try to upload file from UI to check field is mandatory or not?
I tried to research a bit, but has not found a proper solution to this.
What I'm trying to do is to have a HTML.Action in a page like so
Html.Action("Calendar", "GlobalShared")
Inside the action "Calendar", I need to return the result of the html of the traditional calendar control
public ActionResult Calendar(
String ID,
String CssClass,
int CellSpacing,
int CellPadding,
String BorderWidth,
String ShowGridLines,
String ShowTitle,
String DayNameFormat
)
{
System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();
cal.ID = "MyCalendar";
cal.CssClass = "month-view";
cal.CellSpacing = 0;
cal.CellPadding = -1;
cal.BorderWidth = 0;
cal.ShowGridLines = false;
cal.ShowTitle = false;
cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;
}
How can I do this? Btw, I use HTML.Action is because I read that it returns a html string, is that correct or should I be doing some other ways?
Thanks
Edit. Before I attempted this in a controller, I tried the following code in a view .cshtml and it works, but I prefer to move the code into a controller
#{
System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();
cal.ID = "MyCalendar";
cal.CssClass = "month-view";
cal.CellSpacing = 0;
cal.CellPadding = -1;
cal.BorderWidth = 0;
cal.ShowGridLines = false;
cal.ShowTitle = false;
cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;
cal.RenderControl(new HtmlTextWriter(Html.ViewContext.Writer));
}
Edit #2. The reason I want to use that in a controller is because if in the future, i want to hook up an event say "DayRender", I can do it in the controller. I can not do the same in a view without polluting the view page.
Okay. Thanks guys. I figured out. Basically, I need to use #{Html.RenderAction(..)} and in the action itself, use StringBuilder/StringWriter and then return Content(...). Code below
In View
#{Html.RenderAction("Calendar", "GlobalShared");}
In Controller
[ChildActionOnly]
public ActionResult Calendar(
)
{
System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();
cal.ID = "MyCalendar";
cal.CssClass = "month-view";
cal.CellSpacing = 0;
cal.CellPadding = -1;
cal.BorderWidth = 0;
cal.ShowGridLines = false;
cal.ShowTitle = false;
cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;
cal.DayRender += new System.Web.UI.WebControls.DayRenderEventHandler(CalendarDayRender);
StringBuilder sb = new StringBuilder();
using (System.IO.StringWriter sw = new System.IO.StringWriter(sb))
{
System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(sw);
cal.RenderControl(writer);
}
String calHTML = sb.ToString();
return Content(calHTML);
}
private void CalendarDayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
e.Cell.Text = "";
if (e.Day.Date == System.DateTime.Today)
{
e.Cell.CssClass = "today";
System.Web.UI.HtmlControls.HtmlGenericControl h3 = new System.Web.UI.HtmlControls.HtmlGenericControl("h3");
h3.InnerHtml = HttpContext.GetGlobalResourceObject("JTG_DateTime", "JTK_Today") + " " + e.Day.DayNumberText;
e.Cell.Controls.Add(h3);
}
}
Simply move your code
#{
System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();
cal.ID = "MyCalendar";
cal.CssClass = "month-view";
cal.CellSpacing = 0;
cal.CellPadding = -1;
cal.BorderWidth = 0;
cal.ShowGridLines = false;
cal.ShowTitle = false;
cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;
cal.RenderControl(new HtmlTextWriter(Html.ViewContext.Writer));
}
in a view and return that View from your Calendar Action.
public ActionResult Calendar(
String ID,
String CssClass,
int CellSpacing,
int CellPadding,
String BorderWidth,
String ShowGridLines,
String ShowTitle,
String DayNameFormat
)
{
return View("Calendar");
}
You can either create a ViewModel or use ViewBag to transfer these values from Calendar Action to your newly created View
I'm trying to archive my search results for a term by
Using the Bing API in an async controller
Inserting them into database using Entity Framework
using the Bing API and insert them into a database using entity framework. For whatever reason it is returning 50 results, but then it enters 100 results into the database.
My Controller Code:
public class DHWebServicesController : AsyncController
{
//
// GET: /WebService/
private DHContext context = new DHContext();
[HttpPost]
public void RunReportSetAsync(int id)
{
int iTotalCount = 1;
AsyncManager.OutstandingOperations.Increment(iTotalCount);
if (!context.DHSearchResults.Any(xx => xx.CityMarketComboRunID == id))
{
string strBingSearchUri = #ConfigurationManager.AppSettings["BingSearchURI"];
string strBingAccountKey = #ConfigurationManager.AppSettings["BingAccountKey"];
string strBingUserAccountKey = #ConfigurationManager.AppSettings["BingUserAccountKey"];
CityMarketComboRun cityMarketComboRun = context.CityMarketComboRuns.Include(xx => xx.CityMarketCombo).Include(xx => xx.CityMarketCombo.City).First(xx => xx.CityMarketComboRunID == id);
var bingContainer = new Bing.BingSearchContainer(new Uri(strBingSearchUri));
bingContainer.Credentials = new NetworkCredential(strBingUserAccountKey, strBingAccountKey);
// now we can build the query
Keyword keyword = context.Keywords.First();
var bingWebQuery = bingContainer.Web(keyword.Name, "en-US", "Moderate", cityMarketComboRun.CityMarketCombo.City.Latitude, cityMarketComboRun.CityMarketCombo.City.Longitude, null, null, null);
var bingWebResults = bingWebQuery.Execute();
context.Configuration.AutoDetectChangesEnabled = false;
int i = 1;
DHSearchResult dhSearchResult = new DHSearchResult();
List<DHSearchResult> lst = new List<DHSearchResult>();
var webResults = bingWebResults.ToList();
foreach (var result in webResults)
{
dhSearchResult = new DHSearchResult();
dhSearchResult.BingID = result.ID;
dhSearchResult.CityMarketComboRunID = id;
dhSearchResult.Description = result.Description;
dhSearchResult.DisplayUrl = result.DisplayUrl;
dhSearchResult.KeywordID = keyword.KeywordID;
dhSearchResult.Created = DateTime.Now;
dhSearchResult.Modified = DateTime.Now;
dhSearchResult.Title = result.Title;
dhSearchResult.Url = result.Url;
dhSearchResult.Ordinal = i;
lst.Add(dhSearchResult);
i++;
}
foreach (DHSearchResult c in lst)
{
context.DHSearchResults.Add(c);
context.SaveChanges();
}
AsyncManager.Parameters["message"] = "The total number of results was "+lst.Count+". And there are " + context.DHSearchResults.Count().ToString();
}
else
{
AsyncManager.Parameters["message"] = "You have already run this report";
}
AsyncManager.OutstandingOperations.Decrement(iTotalCount);
}
public string RunReportSetCompleted(string message)
{
string str = message;
return str;
}
}
Here is how I am calling it from my asp.net mvc 4 page.
#Ajax.ActionLink("Run Report", "GatherKeywordsFromBing", "DHWebServices",
new { id=item.CityMarketComboRunID},
new AjaxOptions { OnSuccess = "ShowNotifier();", UpdateTargetId = "TopNotifierMessage", HttpMethod = "POST", InsertionMode = InsertionMode.Replace, LoadingElementId = strCityMarketComboProgressID, LoadingElementDuration = 1000 },
new { #class = "ViewLink" })
<span class="ProgressIndicator" id="#strCityMarketComboProgressID"><img src="#Url.Content("~/Content/img/SmallBall.gif")" alt="loading" /></span>
For whatever reason all of
Try saving only once:
foreach (DHSearchResult c in lst)
{
context.DHSearchResults.Add(c);
}
context.SaveChanges();
Also there's nothing asynchronous in your code, so there's no point of using asynchronous controller. Not only that it won't improve anything but it might make things worse.