You need to sign in to do that
Don't have an account?
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.
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
Hi,
Thanks,
Devendra
Error Message:Error: Compile Error: invalid ID field: Cus_obj_Record_ID at line 38 column 16
Thanks,
Lavanya
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
Regards,
Lavanya.
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
Hi Devendra,
Thanks for the reply. Can you please tell me more to resolve this.waiting for your reply.
Regards,
Lavanya.
Delete siteObj;
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
Hi Devendra,thanks a lot its working.