• jamesob5
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

In my .net application I'm trying to attach a campaign to a new lead using the API. Creating new lead works fine when I'm not trying to pass a campaign to it. I'm trying to locate the campaign by id, load t into a campaign object, pass that campaign object to the lead and create lead. I do locate the campaign using the query but I may be missing a step. I get error: "Invalid foreign key relationship name Campaign".

 

Please help.

 

 

 The code


objSF.Url = l.serverUrl;
objSF.SessionHeaderValue = new SessionHeader();
objSF.SessionHeaderValue.sessionId = l.sessionId;
GetUserInfoResult userInfo = l.userInfo;

// Adding new lead to SalesForce.com //
sObject[] aLeads = new sObject[1];
Lead lead = new Lead();
lead.FirstName = FirstName.Length > 25 ? FirstName.Substring(0, 25) : FirstName;
lead.LastName = LastName.Length > 25 ? LastName.Substring(0, 25) : LastName;
lead.Company = CompanyName.Length > 50 ? CompanyName.Substring(0, 50) : CompanyName;
lead.Title = Position;
lead.State = StateAbbr;
lead.PostalCode = Zipcode;
lead.Phone = "NA";
lead.LeadSource = "Web";
if (CameFrom == "Demo") strLeadStatus = "New Lead";
lead.Status = strLeadStatus;
string strLeadSoureDetail = "Community";
if (CameFrom == "Demo") strLeadSoureDetail = "Online Demo";
lead.Lead_Source_Details__c = strLeadSoureDetail;
lead.Email = Email;
lead.Practice_Specialties__c = "Unknown";
lead.Num_Providers__c = 1;
objSF.Url = l.serverUrl;
objSF.SessionHeaderValue = new SessionHeader();
objSF.SessionHeaderValue.sessionId = l.sessionId;

// Adding campaign to the lead //
//Web - Community Campaign ID: 701400000009wgw
//Web - Online Demo Campaign IS: 701400000009kBS
string strCampID = "701400000009wgw";

if (CameFrom == "Demo") strCampID = "701400000009kBS";
QueryResult qr = new QueryResult();
objSF.QueryOptionsValue = new QueryOptions();
objSF.QueryOptionsValue.batchSize = 250;
objSF.QueryOptionsValue.batchSizeSpecified = true;
qr = objSF.query("select id, Name from Campaign where id='" + strCampID + "'");

if (qr.size > 0)
{
for (int i = 0; i < qr.records.Length; i++)
{
Campaign camp = (Campaign)qr.records[i];
lead.Campaign = camp;
}
}

// Community Section //
lead.First_name__c = FirstName.Length > 25 ? FirstName.Substring(0, 25) : FirstName;
lead.Last_Name__c = LastName.Length > 25 ? LastName.Substring(0, 25) : LastName;
lead.NGC_ProfileID__c = ProfileID.ToString();
lead.Username__c = UserName.Length > 50 ? UserName.Substring(0, 50) : UserName;
lead.Primary_Email__c = Email;
lead.Company_name__c = CompanyName.Length > 50 ? CompanyName.Substring(0, 50) : CompanyName;
lead.Industry__c = IndType.Length > 50 ? IndType.Substring(0, 50) : IndType;
if (PositionDesc != null)
{
lead.Position__c = PositionDesc.Length > 30 ? PositionDesc.Substring(0, 30) : PositionDesc;
}
lead.Created_Date__c = DateTime.Now;
aLeads[0] = lead;

SaveResult[] sr = objSF.create(aLeads);

 

 

Dear folks
I am trying to update some contact records, and it seems any attempt to update the boolean field values are ignored?  (I can see various solutions for other environments, but none for VB).  Basically I am assigning the fields with w_contact("fieldname").value = "New VAlue" for string fields, but I've tried any permutation of fields for the boolean values (eg True/False/1/0 etc) with no joy.  THese fields are customer fields.  I can read the values OK.
Can anyone tell me the secret?!
Thanks
DJN
  • July 05, 2006
  • Like
  • 0
The code below runs fine and prints the ID of the newly created object, but when I look in the app, AnnualRevenue is blank!

sforce.Account newAcc = new sforce.Account();
newAcc.Name = "Test Account";
newAcc.AnnualRevenue = 10000;
sforce.SaveResult [] sr = svc.create ( new sforce.sObject[] { newAcc } );
if(sr[0].success)
{
Console.WriteLine("new id of account is {0}", sr[0].id); } else {
Console.WriteLine("error creating account {0}", sr[0].errors[0].message);
}


What's happening is that for field type's that do not support being null in .NET, the generated .NET code includes an additional property that indicates if it should send the value. Unfortuanly even if you explicitly set a value, the property that says to send the value doesn't get set. You need to also set that property as well. These properties have "Specified" appended to the property name they apply to, so the above example should be

sforce.Account newAcc = new sforce.Account();
newAcc.Name = "Test Account";
newAcc.AnnualRevenue = 10000;
newAcc.AnnualRevenueSpecified = true;
sforce.SaveResult [] sr = svc.create ( new sforce.sObject[] { newAcc } );
if(sr[0].success)
{
Console.WriteLine("new id of account is {0}", sr[0].id); } else {
Console.WriteLine("error creating account {0}", sr[0].errors[0].message); }
}

If you run this revised version, you'll see the AnnualRevenue value in the application. Properties of type DateTime, bool, int and double all have these additional specified flags.