+ Start a Discussion
VFVF 

IDE problem

cant we use execute anonymous action from eclipse to debug the testmethod for triggers in Apex class uing force.comIDE
Best Answer chosen by Admin (Salesforce Developers) 
gm_sfdc_powerdegm_sfdc_powerde
You can open the class that contains your test methods, right-click and run tests using "Force.com -> Run tests" option. 

All Answers

gm_sfdc_powerdegm_sfdc_powerde
You can open the class that contains your test methods, right-click and run tests using "Force.com -> Run tests" option. 
This was selected as the best answer
VFVF

Hello,

Thanks for your reply i am able to debug by clicking on run test fro IDE.

 

I have an issue in Apex triggers can u please help me out: 

 

Here is the code of my Apex trigger test class: 

 

public class sampleTest{

static testMethod void WCSFTrigger(){

    Map<String, Individual_Email_Results__c> lgaMap = new Map<String, Individual_Email_Results__c>();

    Individual_Email_Results__c objInsert = new Individual_Email_Results__c();

    objInsert .Hard_Bounce__c = 1; 

    objInsert .Abuse__c = '1';

    objInsert .GlobalUnsubscribe__c = '1';

    objInsert .UniversalUnsubscribe__c = '1';

    objInsert .Unsubscribe__c = '1';

    objInsert .Lead__c = '00Q90000001S4fL';

    objInsert .Contact__c = '00390000001bZ1V';

   

    insert objInsert ;

 

//Here the triggers fires on updation 

    objInsert . Unsubscribe__c = '3'; 

    update objInsert;

 

    Decimal newValue = objInsert .Hard_Bounce__c;//obj.Hard_Bounce__c;

    Decimal oldValue = 2; 

    String contactID = objInsert.Contact__c;//'00390000001bZ1V';

    String leadID = objInsert.Lead__c; 

    

    system.debug(objInsert.Contact__c);

    if(newValue != oldValue)

    {

    

     system.debug(contactID);

    

    if(contactID  != null)

    {

    

         Contact contact = [Select Id, HasOptedOutOfEmail from contact WHERE Id=: contactID ];

         system.debug(contact);

         system.debug(contact.HasOptedOutOfEmail);

         if(contact.HasOptedOutOfEmail == true)

               {

               contact.HasOptedOutOfEmail = false;

                   //system.assertEquals(contact.HasOptedOutOfEmail , false); 

               }

               else

               {

               contact.HasOptedOutOfEmail = true;

                   //system.assertEquals(contact.HasOptedOutOfEmail , true);

               }

               update contact;

    }

    

    if(objInsert.Lead__c!= null)

    {

        Lead lead = [Select Id, HasOptedOutOfEmail from lead WHERE Id=:objInsert.Lead__c];

         if(lead .HasOptedOutOfEmail == true)

               {

                 system.assertEquals(lead .HasOptedOutOfEmail , true); 

               }

               else

               {

                  system.assertEquals(lead .HasOptedOutOfEmail , true); 


               }

               update lead ;

    }

    

     if( (objInsert.Abuse__c != '2') || (objInsert.GlobalUnsubscribe__c != '2') || (objInsert.UniversalUnsubscribe__c != '2') || (objInsert.Unsubscribe__c != '2'))

        {

            if(objInsert.Contact__c!= null)

            {  

               Contact contact = [Select Id, EmailBouncedDate , EmailBouncedReason from contact WHERE Id=:objInsert.Contact__c];

               system.assertEquals( contact.EmailBouncedReason , 'WhatCounts Hard Bounce'); 

                

               update contact;

                   

            }

            if(objInsert.Lead__c!= null)

            {              

               Lead lead= [Select Id, EmailBouncedDate , EmailBouncedReason from lead WHERE Id=:objInsert.Lead__c];

               system.assertEquals( lead.EmailBouncedReason , 'WhatCounts Hard Bounce'); 

               

               update lead;

            }

         

        }

 

 

I have a problem in writing test class for  code which has bold font .Please let me know if there is any issue.

 

 

 

The trigger is:

 

trigger WCSFTrigger on Individual_Email_Results__c (after update) {

Map<String, Individual_Email_Results__c> lgaMap = new Map<String, Individual_Email_Results__c>();

       for (Individual_Email_Results__c objUpdate: System.Trigger.New) {

       

        Individual_Email_Results__c obj= [Select id,Contact__c,Lead__c,Hard_Bounce__c,Abuse__c,GlobalUnsubscribe__c,UniversalUnsubscribe__c,Unsubscribe__c,Hard_Bounce_Event_Date__c  from Individual_Email_Results__c where id= :objUpdate.Id];

        string contactID = obj.Contact__c;

        string leadID = obj.Lead__c;

        Decimal newValue = trigger.new[0].Hard_Bounce__c;

        Decimal oldValue = trigger.old[0].Hard_Bounce__c;

       

        if(newValue != oldValue )

        {

            if(contactID != null)

            {  

               Contact contact = [Select Id, HasOptedOutOfEmail from contact WHERE Id=:contactID ];

               if(contact.HasOptedOutOfEmail == true)

               {

                  contact.HasOptedOutOfEmail = false;

               }

               else

               {

                  contact.HasOptedOutOfEmail = true;

               }

               update contact;

                   

            }

            if(leadId != null)

            {              

               Lead lead = [Select Id, HasOptedOutOfEmail from lead WHERE Id=: leadId];

               if(lead.HasOptedOutOfEmail == true)

               {

                  lead.HasOptedOutOfEmail = false;

               }

               else

               {

                   lead.HasOptedOutOfEmail = true;

               }

               update lead;

            }

             

        }        

        if( (trigger.new[0].Abuse__c != trigger.old[0].Abuse__c) || (trigger.new[0].GlobalUnsubscribe__c != trigger.old[0].GlobalUnsubscribe__c) || (trigger.new[0].UniversalUnsubscribe__c != trigger.old[0].UniversalUnsubscribe__c) || (trigger.new[0].Unsubscribe__c != trigger.old[0].Unsubscribe__c))

        {

            if(contactID != null)

            {  

               Contact contact = [Select Id, EmailBouncedDate , EmailBouncedReason from contact WHERE Id=:contactID ];

               contact.EmailBouncedReason = 'WhatCounts Hard Bounce';

               contact.EmailBouncedDate = datetime.valueOf(obj.Hard_Bounce_Event_Date__c);

               update contact;

                   

            }

            if(leadId != null)

            {              

               Lead lead= [Select Id, EmailBouncedDate , EmailBouncedReason from lead WHERE Id=:leadID ];

               lead.EmailBouncedReason = 'WhatCounts Hard Bounce';

               lead.EmailBouncedDate =  datetime.valueOf(obj.Hard_Bounce_Event_Date__c);

               update lead;

            }

         

        }

        }

       

 

 

Please let me know if any changes has to be done.

I have followed the APEX DOCS TO WRITE THE CODE. I have already made two posts regarding this issue but didnot get any reply.

 

Thanks