-4

Hi Can anyone please tell me how to solve this error.

Code:

public class LeadConversion {

public PageReference RedirecttoLead()     {
    String currentLead = '/' + siteObj.Id;
    PageReference pageRef = new PageReference(currentLead);
    return pageRef;
 }

 private Site__c siteObj,temp_siteObj;
public ID Cus_Account_ID;
public ID Cus_obj_Record_ID;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public LeadConversion(ApexPages.StandardController stdController)
 {
 System.debug('******Voltum******');
         siteObj = (Site__c)stdController.getRecord();
         Cus_obj_Record_ID = siteObj.Id;
}

public void convertLead(){

    Account acc = new Account();
    acc.Name = siteObj.Name;
    acc.CurrencyIsoCode = siteObj.CurrencyIsoCode;

    try 
   { 
    insert acc; 
   }
    Catch (Exception ex1)
    {        
     ex1.getmessage();
    }
    Contact cc = new Contact();
    cc.LastName = siteObj.LastName__c;

    temp_siteObj=[select AccountId from contact where Id ='Cus_obj_Record_ID'];
    Cus_Account_ID = temp_siteObj;
    cc.AccountId= Cus_Account_ID;
   // cc.accountId = siteObj.Name;
    //Id accountId = [select AccountId from Contact where Id = {ID}][0].AccountId; 
    //System.Debug(accountId);

   try 
   { 
    insert cc; 
   }
    Catch (Exception ex2)
    {

     ex2.getmessage();
    }



}

}

Waiting for the reply.

2 Answers 2

3

In this line:

temp_siteObj=[select AccountId from contact where Id ='Cus_obj_Record_ID'];

you are passing a string literal where an id field is expected. Looking at your code, it appears that the property 'Cus_obj_Record_ID' should contain an ID, in which case you can bind it in to the SOQL as follows:

temp_siteObj=[select AccountId from contact where Id =:Cus_obj_Record_ID];

This does assume that there will always be a record returned, which won't be the case if Cus_obj_Record_ID is null - if that is a possibility its better to assign the results to a list and check if there are are records matching, e.g.

List<Contact> conts=[select AccountId from contact where Id =:Cus_obj_Record_ID];
if (conts.size()>0)
{
   temp_siteObj=conts[0];
   // rest of your code here
}
0

I had similar issue - System.debug('LEAD ID' + ar.get('LEADID')); String tempLeadId = (string)ar.get('LEADID'); String leadQuery = 'SELECT LEAD.ID,XYZ__c from LEAD where LEAD.ID = tempLeadId ;

here it happened that the LEADID had leading 0s, which were getting omitted in SOQL formation string.

Modified it to have single quotes wrapping the LEADID. It worked then.

System.debug('LEAD ID' + ar.get('LEADID')); String tempLeadId = (string)ar.get('LEADID'); String leadQuery = 'SELECT LEAD.ID,Delete_Lead_Response_Date__c from LEAD where LEAD.ID = \''+ tempLeadId +'\'';

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .