You need to sign in to do that
Don't have an account?
How to write test Method for delete statement
hi can anybody help me to write Test Method for given below code ,
public PageReference deleteRecord()
{ String customerId=null;
try { customerId=ApexPages.currentPage().getParameters().get('customerId');
if(customerId!=null)
{
List demo = new List(); demo = [Select id,Customer_Id__c From CustomerDemographicsDetail__c where Customer_Id__c=:customerId]; delete demo; List insuredParty = new List(); insuredParty = [Select id,Customer_Id__c From CustomerFinancialDetail__c where Customer_Id__c=:customerId]; delete insuredParty; List survivor = new List(); survivor = [Select id,Customer_Id__c From Customer_Financial_Detail1__c where Customer_Id__c=:customerId]; delete survivor; List retirement = new List(); retirement = [Select Customer_Id__c From Customer_Retirement_Detail__c where Customer_Id__c=:customerId]; delete retirement; List education = new List(); education = [Select Customer_Id__c From Customer_Educational_Goal__c where Customer_Id__c=:customerId]; delete education; List survivorNeeds = new List(); survivorNeeds = [Select Customer_Id__c From Customer_Survivor_Needs__c where Customer_Id__c=:customerId]; delete survivorNeeds; List survivorIncomeProv = new List(); survivorIncomeProv = [Select Customer_Id__c From Survivor_Income_Provision__c where Customer_Id__c=:customerId]; delete survivorIncomeProv; } } catch(Exception e) { ApexPages.addMessages(e); } return null; }
Thanks in advance
Madhulendra
Ive written for the first few lines of the code. Repeat the same for the rest. Hope it fits your requirement
static testMethod void testdeleteRecord() { Customer__c custId = [select Id from Customer__c LIMIT 1]; CustomerDemographicsDetail__c cust1 = new(CustomerDemographicsDetail__c(Customer_Id__c = custId.Id); try{insert cust1;} catch(Exception e){} CustomerFinancialDetail__c insure1 = new(CustomerFinancialDetail__c(Customer_Id__c = custId.Id); try{insert insure1;} catch(Exception e){} Customer_Retirement_Detail__c retire1 = new(Customer_Retirement_Detail__c(Customer_Id__c = custId.Id); try{insert retirek1;} catch(Exception e){} Test.startTest(); delete cust1; delete insure1; delete retire1; Test.stopTest(); }
hi
when I tried to write code it's give an error "Missing id at index : 0"
when I click on error then controller goes to delete cust1;
what I should do next.....
Thanks
this is my test method that getting error while I run Test
{
CustomerContactDetail__c custId = [Select c.Id From CustomerContactDetail__c c LIMIT 1];CustomerDemographicsDetail__c cust1 = new CustomerDemographicsDetail__c(Customer_Id__c = custId.Id);
try{insert cust1;} catch(Exception e){}CustomerFinancialDetail__c insure1 =new CustomerFinancialDetail__c(Customer_Id__c = custId.Id);
try{insert insure1;} catch(Exception e){}Customer_Retirement_Detail__c retire1 = new Customer_Retirement_Detail__c(Customer_Id__c = custId.Id);
try{insert retire1;} catch(Exception e){}Test.startTest();
delete cust1;delete insure1;
delete retire1;Test.stopTest();
}