function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vishvish 

Posting a lead with campaign using Apex API

Hello all,
 
I am having problems tying a campaign to a lead. I am able to get a campaign using the campaignID and then set the campaign on the lead, I dont get any errors but the lead doesnt post in salesforce.
 
I have read the API and searched the discussion boards and cannot find anything useful. I have been struggling with this issue for 2 days and have contacted sales force support as well.
 
 
The code follows.
 
The method to find the campaign using a campaign ID
Code:
    private static Campaign getCampaign(String campaignID) {
     
     log.debug("looking for campaign with id [" + campaignID + "]");
     Campaign campaign = new Campaign();
     try {
      StringBuffer sb = new StringBuffer();
      sb.append("Select Name From Campaign where id = '");
      sb.append(campaignID);
      sb.append("'");
      log.debug("running query: " + sb.toString());
      QueryResult result = binding.query(sb.toString());
      
      if (result.getRecords().length > 0) {
       campaign = (Campaign) result.getRecords(0);
       log.debug("campaign [" + campaign.getName() + "] found");
      }
     } catch (RemoteException e) {
      e.printStackTrace();
     }
  return campaign;
     
    }

 
Here, I set the campaign on the lead and other fields on the lead.
Code:
Lead lead = new Lead();
lead.setCampaign(getCampaign(campaignID));

 I dont see any errors, but the lead doesnt post. Once I comment out setting the campaign, the lead posts successfully.
Please help.
 
Thanks,
-Vish
Venkat PolisettVenkat Polisett
In getCampaign() ->
 
try this statement with the id:
 
sb.append("Select id, Name From Campaign where id = '");