You need to sign in to do that
Don't have an account?
sasham
Data is not inserting in the test class. any help on this (Test class)
I craeted custom button on participant table and link Vf pageto the button . when i clicked on the button , address table will get updated
This is my controller extension and Vf page .i need help on the test calss
This is my controller extension and Vf page .i need help on the test calss
public with sharing class PClass{ public participant__c participant; private ApexPages.StandardController stdControler; public Id Id { get; set; } public PClass(ApexPages.StandardController stdControler){ this.participant = (participant__c)stdControler.getRecord(); this.stdControler = stdControler; } public PageReference InsertAddress(){ try{ participant__c p = [select id, SS_ID__c from participant__c where Id = :participant.Id limit 1]; Registration__c r= [select Id,Address1__c, Address2__c,SS_ID__c from Registration__c where SS_ID__c =:p.SS_ID__c limit 1]; Addresses_c paddress = new Addresses__c(); paddress.participant__c = participant.Id; paddress.Address1__c = r.Address1__c; paddress.Address2__c = r.Address2__c; insert paddress; } catch (Exception e){} return new ApexPages.StandardController(participant).view(); } VF page <apex:page standardController="Participant__c" extensions="PClass" action="{!InsertAddress}" > </apex:page>My test class
@isTest public with sharing class PClass_Test { static TestMethod void AddAddress(){ Registration__c TestRegistration= new Registration__c(); TestRegistration.Name = 'Test Registration'; TestRegistration.SS_ID__c = Decimal.valueOf(30111); TestRegistration.Address1__c='10 Street'; TestRegistration.Address2__c ='15 street'; insert TestRegistration; participant__c TestParticipant = new participant__c(); TestParticipant.FirstName__c ='Test participant'; TestParticipant.SS_ID__c =Decimal.valueOf(30111);; insert TestParticipant; Test.startTest(); ApexPages.StandardController stdController = new ApexPages.StandardController(TestParticipant); PClass pa = new PClass(stdController); System.debug(pa.Id); pa.InsertAddress(); System.debug(pa); Test.stopTest(); try{ Addresses_c padd = [select id, participant__c from Addresses_c where participant__c =:pa.Id limit 1]; } catch (Exception e){} }
All you need to do for the test class is to check both for try block as well as catch block which can be achieved by inserting the corresponding object with not necessary data and try to run both the methods for testing!
Visual Force Page: Test Class:
If this helps you to resolve your problem, please choose this as the best answer!
Thank you!
All Answers
All you need to do for the test class is to check both for try block as well as catch block which can be achieved by inserting the corresponding object with not necessary data and try to run both the methods for testing!
Visual Force Page: Test Class:
If this helps you to resolve your problem, please choose this as the best answer!
Thank you!