You need to sign in to do that
Don't have an account?
Need help with first trigger
Hello,
I am new to coding on the force platform. I am using the Enterprise Edition with Non-Profit Starter Pack.
I've written a trigger in my Sandbox:
trigger MakeParentsActiveTrigger on Contact (after insert, after update) {
//Get list of Consumer IDs that the trigger is acting upon
List<ID> consumerids = New List<ID>();
List<ID> ParentIds = New List<ID>();
for(Contact o : Trigger.new) {
//Add Parents Ids to a list if the contact is an active consumer
if(o.QSAC_active__c == TRUE && o.RecordTypeID == '012A000000179ETIAY') {
ParentIds.add(o.Primary_Parent_Guardian__c);
ParentIds.add(o.Secondary_Parent_Guardian__c);
}
}
//Retrieve Parents Active status
List<Contact> ParentInfo = [SELECT id, QSAC_active__c FROM Contact WHERE id in :ParentIds];
//Update the Parents Active status
for(integer i = 0 ; i < ParentInfo.size(); i++){
ParentInfo[i].QSAC_active__c = FALSE;
}
update ParentInfo;
}
But I have no idea how to tell if it is working, or if it is ever called. Furthermore, I'm not sure if I need a class when it seems the trigger should be able to stand alone. I'm also confused about "reaching 75%" of something before I can copy it into my production database. Any help would be appreciated.
You do need a class. Why? For the 75% you heard about. What they're referring to is "code coverage", which is achieved by one or more "test methods", which empirically "prove" that your trigger is indeed firing in the manner which you expect.
You have a few small problems with your code, though:
Now, given that, your test method just has to:
1) Insert two new contacts, a mother and a father (or whatever), set the flags to true.
2) Insert one new contact, with the specified mother/father, and of the correct record type.
3) Query back the two contacts, and make sure the flag is set to false.