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
LavanyaLavanya 

Error: Compile Error: invalid ID field: Cus_obj_Record_ID at line 40 column 22

Hi , I am tring to do the same functionslity as lead. I have created a custom object whhich as a custom button"convert". When we click "convert" button i must creat a account and related contact. But when doing this I am not getting the Account name in contact.

Error Message :

 

Error: Compile Error: invalid ID field: Cus_obj_Record_ID at line 40 column 22

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('******welcome******');
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();
}

}

}

 

Anyone pls tell me how to resolve this issue.

Thanks,

Regards,

Lavanya.

Best Answer chosen by Admin (Salesforce Developers) 
Devendra@SFDCDevendra@SFDC

Hi,

 

If you need to give a inserted AccountId to the new Contact then you can write as,

 

try{

    insert acc; // pick this acc

}catch(){

 

}

Contact cc = new Contact();

cc.LastName = siteObj.LastName__c;

cc.AccountId = acc.Id // Inserted Account id is given to this field

 

try{

    insert cc;

}catch(){

 

}

 

Thanks,

Devendra

 

 

Thanks

All Answers

Devendra@SFDCDevendra@SFDC

Hi,

 

temp_siteObj=[select AccountId from contact where Id ='Cus_obj_Record_ID'];
Cus_Account_ID = temp_siteObj.AccountId; // this change is needed
cc.AccountId= Cus_Account_ID;

 

Thanks,

Devendra

LavanyaLavanya
Hi Devendra, thanks for the reply. After made these change I am the same error.
Error Message:Error: Compile Error: invalid ID field: Cus_obj_Record_ID at line 38 column 16

Thanks,
Lavanya
Devendra@SFDCDevendra@SFDC

Hi,

 

If you need to give a inserted AccountId to the new Contact then you can write as,

 

try{

    insert acc; // pick this acc

}catch(){

 

}

Contact cc = new Contact();

cc.LastName = siteObj.LastName__c;

cc.AccountId = acc.Id // Inserted Account id is given to this field

 

try{

    insert cc;

}catch(){

 

}

 

Thanks,

Devendra

 

 

Thanks

This was selected as the best answer
LavanyaLavanya
Hi Devedra, Thanks a lot the reply. Its working , one more information once the record as been converted that record should not be in the lead tab. For this what we have do. Please reply thanks a lot.

Regards,
Lavanya.
Devendra@SFDCDevendra@SFDC
Hi,

At the last, you need to perform delete operation.

delete objInstance; // delete the record which you are trying to delete

you can put those statements in try/catch block;

Thanks,
Devendra
LavanyaLavanya

Hi Devendra,
Thanks for the reply. Can you please tell me more to resolve this.waiting for your reply.
Regards,
Lavanya.

LavanyaLavanya
Hi Devendra, thanks for the reply. I have given like this. Is this correct
Delete siteObj;
Devendra@SFDCDevendra@SFDC

Hi,

 

Do you want to delete siteObj?

 

If yes then it's correct way to do it.

 

try{

    delete siteObj;

}catch(){

// catch Exception

}

 

Thanks,

Devendra

 

 

LavanyaLavanya

Hi Devendra,thanks a lot its working.