+ Start a Discussion
cdavis@elt.comcdavis@elt.com 

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

Can anyone give me a Test Class for this? I don't yet understand Test Classes.

 

trigger Share_Imp_Contact on Implementation__c (after insert, before update) {
if(trigger.isUpdate){
    Set<String> impIds = new Set<String>();
    for (Implementation__c imp : Trigger.new) {
        impIds.add(imp.Id);
    }
    Implementation__Share[] doomedSharing = [select id, RowCause from Implementation__Share where Implementation__Share.ParentId IN :impIds and RowCause = 'Customer_Portal__c']; 
    Database.delete(doomedSharing);
}
List<Implementation__Share> implementationShares = new List<Implementation__Share>();
  for(Implementation__c implementation : trigger.new){
    Implementation__Share impAccountShare = new Implementation__Share();
    impAccountShare.ParentId = Implementation.Id;
        String ImpContact = Implementation.Implementation_Contact__c;
        if(ImpContact != NULL){
        if([SELECT COUNT() FROM User WHERE contactid = :ImpContact]>0){
        String ImpUserId = [SELECT Id FROM User WHERE contactid = :ImpContact].Id;
    impAccountShare.UserOrGroupId = ImpUserId;
    impAccountShare.AccessLevel = 'edit';
    impAccountShare.RowCause = Schema.Implementation__Share.RowCause.Customer_Portal__c;
    implementationShares.add(impAccountShare);
    }}}
  Database.SaveResult[] implementationShareInsertResult = Database.insert(implementationShares,false);
}

I have 2 more triggers I'm trying to get up, but i'm sure I can figure those out if someone helps me with these.

I have been scourging the forums and I have found some examples, but I'm having problems following them and relateing them back to mine.

This does work in my sandbox.

cdavis@elt.comcdavis@elt.com

bump :smileyvery-happy: