You need to sign in to do that
Don't have an account?
uHaveOptions
Test class help on trigger
I'm not that familiar create test class yet. Hope you guys can help me with this. Can you guys help me?
trigger primaryContactOwnership on MRG_Ownership__c (after insert,after update) { ownerTrigger(); public void ownerTrigger(){ List<Id> primaryOwnershipIdList = new List<Id>(); List<Id> relatedPropertyIdList = new List<Id>(); for(MRG_Ownership__c ownership : Trigger.New) { if(ownership.Primary_Contact__c == true && (Trigger.Old == null || Trigger.OldMap.get(ownership.Id) == null || Trigger.OldMap.get(ownership.Id).Primary_Contact__c != true)) // To handle null scenario { primaryOwnershipIdList.add(ownership.Id); relatedPropertyIdList.add(ownership.Property__c); Property__c property= [select id, Primary_Contact__c from Property__c WHERE id =:ownership.Property__c limit 1]; property.Primary_Contact__c=ownership.contact__c; update property; } } List<MRG_Ownership__c> relatedOwnershipList = [Select Id, Primary_Contact__c From MRG_Ownership__c Where Property__c in :relatedPropertyIdList And Primary_Contact__c = true And Id Not in :primaryOwnershipIdList]; if(relatedOwnershipList.size() > 0) { for(MRG_Ownership__c ownership : relatedOwnershipList) ownership.Primary_Contact__c = false; update relatedOwnershipList; } } }
You may also need to add code to do AFTER update and bulk operation and negative tests.
All Answers
You may also need to add code to do AFTER update and bulk operation and negative tests.