function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bharath kuamarbharath kuamar 

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;                                   
    }   
}
Best Answer chosen by Admin (Salesforce Developers) 
SFDC_EvolveSFDC_Evolve

@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

SFDC_EvolveSFDC_Evolve

@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

This was selected as the best answer
bharath kuamarbharath kuamar

Thanks a lot, it worked :)