+ Start a Discussion

Test class help needed!

I am trying to write a test class on the following trigger. I created an account and updated it by changin the prospect stage value and the trigger is called. But the deletion is not happening as I did not take care of the attachments. Can anyone please guide me..thanks in advance!!





trigger tgr_Account_After on Account (after insert, after update ){//before delete) {
     //Disable Switch for this trigger managed by Custom Setting
   if(TriggerSwitchSetting__c.getInstance('tgr_Account_After') != null
                && TriggerSwitchSetting__c.getInstance('tgr_Account_After').Disable__c ==true){
        return;    }
    // declare the variables
    set<id> setAccntid = new set<id>();
    set<id> setAAid = new set<id>();
    list<echosign_dev1__SIGN_Agreement__c> listAgreement = new list<echosign_dev1__SIGN_Agreement__c>();
    // prepare the set of Account for the matching criteria
    // call this code when Account is updated and the prospect stage changes and the value is "Cancelled Appointment"
    for(Account acc : trigger.new){
        if(trigger.isupdate && acc.Prospect_Stage_c__c != trigger.oldMap.get(acc.Id).Prospect_Stage_c__c && acc.Prospect_Stage_c__c == String_Constant__c.getInstance('Cancel_Appointment').String_Value__c){
    // get the Drafted Agreement records for the Cancelled accounts
        for(New_Appoinment_pacakge__c AA:[select id, Account__c from New_Appoinment_pacakge__c where Account__c in: setAccntid]){
        // get the Agreement records which are to be deleted
        for(echosign_dev1__SIGN_Agreement__c agreement:[select id, Agency_Agreement__c from echosign_dev1__SIGN_Agreement__c where Agency_Agreement__c in: setAAid]){
        // check if the retrieved list is not empty
            delete listAgreement;