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

HI
Help me with the testclass for the trigger
trigger updateOpportunity on Preference__c (after insert)
{
if (Trigger.isAfter)
{
Map<String, String> map_pref = new Map<String, String>();
for (Preference__c oPref : Trigger.new)
{
map_pref.put(oPref.Opportunity__c, oPref.Id);
}
List<Opportunity> list_opp = new List<Opportunity>();
for (Opportunity opp : [Select Id, Preference__c,
Preference_Associated__c
From
Opportunity
Where
Id IN : map_pref.keySet()])
{
opp.Preference__c = map_pref.get(opp.Id);
opp.Preference_Associated__c = true;
list_opp.add(opp);
}
if (list_opp.size() > 0) update list_opp;
}
}
@isTest
private class test_udpateOpp
{
static testMethod void test_updateopp (){
// Create Opp
Opportunity Opp = new Opportunity (Name = 'Opp'); // Insert all the Mandatory fields
insert opp;
Preference__c Pr = new Preference__c (Opportunity__c = opp.Id);
insert Pr;
}
}
Note . :- All You need to do is .. Create the Data in teh test Class in a way that Query will return atleast One record.
Thanks
SFDC_Evolve
All Answers
@isTest
private class test_udpateOpp
{
static testMethod void test_updateopp (){
// Create Opp
Opportunity Opp = new Opportunity (Name = 'Opp'); // Insert all the Mandatory fields
insert opp;
Preference__c Pr = new Preference__c (Opportunity__c = opp.Id);
insert Pr;
}
}
Note . :- All You need to do is .. Create the Data in teh test Class in a way that Query will return atleast One record.
Thanks
SFDC_Evolve
Thanks a lot, it worked :)