You need to sign in to do that
Don't have an account?
Invalid foreign key relationship name Campaign
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
String FirstName = txtFirstname.Text;
String LastName = txtLastname.Text;
String Company = txtCompany.Text;
String EmailAddress = txtEmailAddress.Text;
if (login() == true)
{
sforce.QueryResult _qr = null;
binding.QueryOptionsValue = new sforce.QueryOptions();
binding.QueryOptionsValue.batchSize = 1;
binding.QueryOptionsValue.batchSizeSpecified = true;
_qr = binding.query("Select id, Name from Campaign where Name = 'Test 1'");
for (int x = 0; x < _qr.records.Length; x++)
{
sforce.Campaign Update_c = new Campaign();
sforce.Campaign c = (sforce.Campaign)_qr.records[x];
Update_c.Id = c.Id;
Lead lead;
sObject[] leads = new sObject[1];
for (int j = 0; j < leads.Length; j++)
{
lead = new Lead();
lead.FirstName = FirstName;
lead.LastName = LastName;
lead.Company = Company;
lead.Email = EmailAddress;
lead.LeadSource = "Test";
lead.Campaign = Update_c;
// lead.Campaign = "70120000000AZc3AAG";
leads[j] = lead;
}
SaveResult[] sr = binding.create(leads);
for (int j = 0; j < sr.Length; j++)
{
if (sr[j].success)
{
Debug.WriteLine("Lead successful added to Salesforce");
}
else
{
for (int i = 0; i < sr[j].errors.Length; i++)
{
//Get all the next error
Error err = sr[j].errors[i];
Debug.WriteLine(err.message.ToString());
}
}
}
}
}
}
}
Here is your sample code.
QueryResult _qr = null;
sfdc.QueryOptionsValue = new QueryOptions();
sfdc.QueryOptionsValue.batchSize = 1;
sfdc.QueryOptionsValue.batchSizeSpecified = true;
_qr = sfdc.query("Select c.Id, c.Name from Campaign c where name = 'Email Blast'");
CampaignMember Update_c = new CampaignMember();
for (int x = 0; x < _qr.records.Length; x++)
{
Campaign c = (Campaign)_qr.records[x];
Lead lead;
sObject[] leads = new sObject[1];
for (int j = 0; j < leads.Length; j++)
{
lead = new Lead();
lead.FirstName = "Case-";
lead.LastName = "02870653_0";
lead.Company = "ABC";
lead.Email = "address@gmail.com";
lead.LeadSource = "Web";
leads[j] = lead;
}
SaveResult[] sr = sfdc.create(leads);
for (int j = 0; j < sr.Length; j++)
{
if (sr[j].success)
{
ErrorInfo = "Lead successful added to Salesforce";
Update_c.CampaignId = c.Id;
Update_c.LeadId = sr[j].id;
SaveResult[] srCmp = sfdc.create(new sObject[]{ Update_c });
for (int i = 0; i < sr.Length; i++)
{
if (sr[i].success)
{
ErrorInfo = ErrorInfo + "Campaign added";
}
}
}
else
{
for (int i = 0; i < sr[j].errors.Length; i++)
{
//Get all the next error
Error err = sr[j].errors[i];
ErrorInfo = err.message.ToString();
}
}
}
}
}