function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sarah RobertsonSarah Robertson 

HELP!!

Hi Im writing a trigger for the cases object which looks for a matching sname and matches the appropriate account for some reason I'm only getting 37 % coverage with my test class. 
Where am i going wrong this is drivign me a bit potty ! I've underlined the parts of the trigger that are covered
Here's my trigger :
trigger UpdateRelatedAccountTrigger on Case (before update,before insert) {
  
Try{

Account a = [select ID, Messina_Short_Name__c,  Name from Account where Messina_Short_Name__c = :trigger.new[0].Messina_Short_Name__c ];

for(Case c1 : trigger.new){

if((
    
    c1.Messina_Short_Name__c!=c1.Messina_Sname__c
  )){


c1.Account_Reference__c= a.ID;
c1.AccountId=a.ID;
   
}
}
Test Class


@isTest
public class UppdateAssignedAccountCaseClass {
    static testMethod void  UpdateCustomSyncHandler() {
        Account acc1 = new Account();
        acc1.Name = 'test account';
        insert acc1;
        system.debug('insert acc1 is success');



           
        Opportunity Opp1 = new Opportunity();
        Opp1.Credit_Check_Requested__c =FALSE;
        Opp1.Name = 'testOpp';
        Opp1.AccountId = acc1.Id;
        Opp1.StageName = 'Stage 0: Lead';
        Opp1.Super_Group__c='Network';
        Opp1.Resource_Group__c='MSP';
        Opp1.CloseDate = system.Today();
        
        Opp1.LeadSource='Marketing';
        insert Opp1;        
        system.debug('insert opp1 success');
        
        Product2 Pro1 = new Product2();
        Pro1.Name = 'Broadband Internet No Resilience';
       
       
       
        pro1.isActive = True;
        Insert pro1;
        system.debug('insert pro1 is success');       
        
        Pricebook2 pb = new pricebook2();
        pb.Name = 'Test Pricebook';
        pb.description = 'Test Pricebook';
        pb.isActive = True;
        insert pb;
        system.debug('pb value is'+ pb.Id);
        system.debug('insert pricebook2 is success');

        Id pricebookId = Test.getStandardPricebookId();        

        PricebookEntry StandardPriceBookEntry = new PricebookEntry();
        StandardPriceBookEntry.Pricebook2Id = pricebookId;
        StandardPriceBookEntry.Product2Id = pro1.Id;
        StandardPriceBookEntry.UnitPrice = 25;
        StandardPriceBookEntry.IsActive =True;        
        insert StandardPriceBookEntry;
        system.debug('insert StandardPriceBookEntry');

        PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=pro1.id, unitprice=20, isActive = True);
        insert pbe;
        system.debug('insert pbe is success');





       

        


        
             Case C1 = new Case(); 
        //C1.Opportunity_Name__r.Id = Opp1.Id;
       // C1.RecordType.Id='012w0000000V6vq';
        C1.Origin='Web';
        C1.Messina_Short_Name__c='SARAH';
       
        insert C1;       
        system.debug('insert C1 success');
        
        C1.Origin='Web';
        C1.Messina_Short_Name__c='SARAH';
       
       update C1;
        
        }}


 
Sarah RobertsonSarah Robertson
sorry ignore this i think i found the issue