You need to sign in to do that
Don't have an account?

I am new to test Class and i have a problem with the test class for a trigger
This is my trigger
trigger UpdatePrimaryApllicationAllocationSet on Primary_Application_Allocation__c (after insert,after delete) {
list<id> lst = new list<id>();
if(trigger.isInsert){
for(Primary_Application_Allocation__c paa : trigger.new) {
lst.add(paa.opportunity__c);
}}
if(trigger.isDelete){
for(Primary_Application_Allocation__c paa : trigger.old) {
lst.add(paa.opportunity__c);
}
}
list<Opportunity> opplst = new list<Opportunity>();
opplst=[SELECT Primary_Application_Allocation_Set__c FROM Opportunity where Id in :lst];
if(trigger.isInsert) {
for(Primary_Application_Allocation__c paa : trigger.new) {
for(Opportunity o : opplst) {
if(paa.Opportunity__c == o.Id) {
o.Primary_Application_Allocation_Set__c = true;
}
}
}
update opplst;
}
if(trigger.isDelete) {
for(Primary_Application_Allocation__c paa : trigger.old) {
for(Opportunity o : opplst) {
if(paa.Opportunity__c == o.id) {
o.Primary_Application_Allocation_Set__c = False;
}
}
}
update opplst;
}
}
and down i have written a test class but it is totally mess cause i am unaware of test class can any one help me in doing this..
@isTest
public class UpdatePrimaryApllicationAllocationSet {
static testMethod void UpdatePrimaryApllicationAllocationSet() {
Test.startTest();
Primary_Application_Allocation__c paa = new Primary_Application_Allocation__c(name='sample');
opportunity o = [select name,oppotunity from opportunity where o.opportunity = paa.opportunity];
insert paa;
update o;
Test.stopStart();
}
}
trigger UpdatePrimaryApllicationAllocationSet on Primary_Application_Allocation__c (after insert,after delete) {
list<id> lst = new list<id>();
if(trigger.isInsert){
for(Primary_Application_Allocation__c paa : trigger.new) {
lst.add(paa.opportunity__c);
}}
if(trigger.isDelete){
for(Primary_Application_Allocation__c paa : trigger.old) {
lst.add(paa.opportunity__c);
}
}
list<Opportunity> opplst = new list<Opportunity>();
opplst=[SELECT Primary_Application_Allocation_Set__c FROM Opportunity where Id in :lst];
if(trigger.isInsert) {
for(Primary_Application_Allocation__c paa : trigger.new) {
for(Opportunity o : opplst) {
if(paa.Opportunity__c == o.Id) {
o.Primary_Application_Allocation_Set__c = true;
}
}
}
update opplst;
}
if(trigger.isDelete) {
for(Primary_Application_Allocation__c paa : trigger.old) {
for(Opportunity o : opplst) {
if(paa.Opportunity__c == o.id) {
o.Primary_Application_Allocation_Set__c = False;
}
}
}
update opplst;
}
}
and down i have written a test class but it is totally mess cause i am unaware of test class can any one help me in doing this..
@isTest
public class UpdatePrimaryApllicationAllocationSet {
static testMethod void UpdatePrimaryApllicationAllocationSet() {
Test.startTest();
Primary_Application_Allocation__c paa = new Primary_Application_Allocation__c(name='sample');
opportunity o = [select name,oppotunity from opportunity where o.opportunity = paa.opportunity];
insert paa;
update o;
Test.stopStart();
}
}
Please see the test class below...You'll may to populate correct(valid/required)fields while inserting test data into Account/Opportunity/Custom Object
http://simplyforce.blogspot.in/2013/06/test-methods-what-why-and-how.html