You need to sign in to do that
Don't have an account?
![devrequirement devrequirement](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Error in one of the Web Service method- System.StringException :Invalid id
In the following method within a webservice, I am getting an error when trying to insert new lead and the error shows from salesforce webservice as following
System.StringException : Invalid Id
For the following class, it's the second red higlighted line.
Please let me know if anyone has any knowledge on how we might tackle this problem.
Thank you!
public static EWebAPIUtils.APILeadInsert insertLead(String companyName, String partnerName, String street, String city, String state, String zip, String country, String website, String phone, String fax, Integer noOfEmployees, String sicCode, String primarySector, String industry, String primaryVertical, String firstName, String lastName, String title, String email, String primaryProduct, String partnerSiteId, String partnerEmailAddress, Date expectedCloseDate, Decimal budget, String region, Decimal annualRevenue, String campaignId)
{
Integer year = math.mod(date.today().year(),100);
String campName = 'NA_VAR_FY'+year;
System.debug('campName :'+campName);
try{
campaignId = [Select Id From Campaign where name = :campName].id;
}catch(Exception e)
{
System.debug('Record not found');
}
Savepoint sp;
Id ruleId;
EWebAPIUtils.APILeadInsert result = new EWebAPIUtils.APILeadInsert();
Lead newLead = new Lead();
newLead.Company = companyName;
newLead.Partner_Name__c = partnerName;
newLead.Street = street;
newLead.City = city;
newLead.State = state;
newLead.PostalCode = zip;
newLead.Country = country;
newLead.Website = website;
newLead.Phone = phone;
newLead.Fax = fax;
if(noOfEmployees != null)
{
newLead.NumberOfEmployees = noOfEmployees;
}
newLead.Primary_SIC_Code__c = sicCode;
newLead.Primary_Sector__c = primarySector;
newLead.Primary_Industry__c = industry;
newLead.Primary_Vertical__c = primaryVertical;
newLead.FirstName= firstName;
newLead.LastName= lastName;
newLead.Title = title;
newLead.Email = email;
newLead.Solution__c= primaryProduct;
newLead.Partner_Site_ID__c = partnerSiteId;
newLead.Partner_Email_Address__c = partnerEmailAddress;
newLead.Expected_Close_Date__c = expectedCloseDate;
if(budget != null)
{
newLead.Budget__c = budget;
}
newLead.Region__c = region;
if(annualRevenue != null)
{
newLead.AnnualRevenue = annualRevenue;
}
newLead.Lead_Type__c = 'Partner';
sp = Database.setSavepoint();
try{
//get the Id for the Standard Assignment Rule from Organization
ruleId = [Select Id From AssignmentRule where name = 'Universal Lead Assignment Rule'].id;
}catch(Exception ex)
{
System.debug('Assignment Rule not found');
}
//Use DMLOptions to provide exta infomation during a transaction.
//Create DMLoptions object
Database.DMLOptions dmo = new Database.DMLOptions();
//AssignmentRuleHeader specifies the Assignment Rule to be used when the lead is created.
dmo.AssignmentRuleHeader.assignmentRuleId = ruleId;
//Sets the DMLOptions object for the sObject
newLead.setOptions(dmo);
try{
insert newLead;
CampaignMember objCampaignMember = new CampaignMember();
objCampaignMember.CampaignId = campaignId;
objCampaignMember.LeadId = newLead.Id;
insert objCampaignMember;
result.iReturnCode = EWebAPIUtils.STATUS_CREATED;
result.strMessage = EWebAPIUtils.LEAD_INSERTED_SUCCESSFULLY ;
EWebAPIUtils.APILeadInsert objAPILeadInsert= result.insertLead(newLead.id,result.iReturnCode,result.strMessage );
return objAPILeadInsert;
}catch(QueryException e)
{
//We reached here as there was some exception occured.
Database.rollback(sp);
result.iReturnCode = EWebAPIUtils.STATUS_ISE;
result.strMessage = EWebAPIUtils.LEAD_INSERT_FAILED ;
return result.insertLead(newLead.id,result.iReturnCode,result.strMessage);
}
}
Hi
Salesforce is not case sensitive. you try change campignId to different name.