• Vinnie B
  • NEWBIE
  • 70 Points
  • Member since 2013
  • Salesforce Specialist
  • Save The Bay

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 25
    Questions
  • 60
    Replies
I know this has got to be simple but I just can't figure it out after hacking away for an hour.  I am not experienced at this.

I'm simply trying to override the New button on a custom object to a URL which pre-populates the Name field.  The URL was easy to develop (below).  It works just like the standard New button but one field is populated with some text.  (We use a workflow rule to set the Name field so there's no need for the user to enter anything.)

  https://na18.salesforce.com/a0o/e?Name=[Set%20by%20Workflow%20Rule]&retURL=%2Fa0o%2Fo

When I want to change the default button it asks me for a VF page.  I have tried creating a simple VF page that just redirects to the URL above.  I'm a pretty novice VF developer and this simple task has got me struggling.

Thanks!!
// 
// AutoCaseCreate.cls --- can be scheduled to run at any time interval
//

global class AutoCaseCreate implements Schedulable {

    // Callable from a Unit Test
    public void execute() {
        // Find the Contacts with Related Sales Tax orgs,
        // so that we can assign a new Case to it
        list<Group> USTRID = [SELECT Email,Id,Name,Type FROM Group WHERE Type =:'queue' AND Name=:'USTR' limit 1];
        
        for(contact con : [SELECT Id, (SELECT Id, Name FROM Sales_Tax_Orgs__r ) FROM Contact
                             WHERE Id IN (SELECT Contact__c from Sales_Tax_Org__c WHERE Name != '')])
   
        {
            // Create a new Case for every contact related to sales tax orgs
            Case c = new Case(
                Priority = 'Medium',
                Status = 'New',
                Subject = 'USTR: Initial EOM Request',
                OwnerId = USTRID[0].id,
                Category__c = 'Accounting',
                Sub_Category__c = 'University Sales Tax Reporting',
                Origin = 'YSS USTR Initiated',  
                ContactId = con.id
               
            );
            // Try to insert our Case
            try {
                insert c;
            } catch (DMLException ex) {
                // Handle the error
            }
        }
    }

    global void execute(SchedulableContext sc) {
        execute();
    }
}
Here is my code for a schedule class. I'm not an expert in coding and i'have written this code with the help of some existing forums. It would be very helpful if you guys suggest me how to write the test class for this.

Thanks
 
I need help with test class for the below trigger. some one please help me. Many thanks guys.
 
trigger UpdateCR on Case  (before update) {

        Map<String, Schema.RecordTypeInfo > caseRecordTypes = Case.sObjectType.getDescribe().getRecordTypeInfosByName();

        Id recordTypeId = caseRecordTypes.get('US Cases Locked RT').getRecordTypeId();

         for ( Case c : Trigger.new) {

           if (c.CF_Tracking__c != null ){
        
              if( c.Status == 'Closed') {

                               c.RecordTypeId = recordTypeId;

        }

    }

}


}

 
I'm trying to create a class and method that will update a field on a record when a picklist value is changed.  I get the Too many SOQL queries error.

It is called by the following trigger:

trigger triggerUpdateTravelChange on Travel_Detail__c (after update, before update) {
    Travel_Detail__c[] travel_details = Trigger.new;
    If(Trigger.Isafter){
        //Updates the Change Travel Ticket Date and 
        //Increments the Change Travel Ticket Revision
        //on the Travel Ticket
        UpdateTravelChange.findTravelDetail(travel_details);
        updateTravelDetailStatus.updateTravelTicket(travel_details);

//TravelCalendarUpdate.TravelDetail(travel_details);

    }
    If(Trigger.Isbefore){
        //Updates the Change Revision and Change Date Fields
        // on the Travel Detail Record
        TravelDetailBooked.updateBooked(travel_details);
    }
}

Apex Class

trigger triggerUpdateTravelChange on Travel_Detail__c (after update, before update) {
    Travel_Detail__c[] travel_details = Trigger.new;
    If(Trigger.Isafter){
        //Updates the Change Travel Ticket Date and 
        //Increments the Change Travel Ticket Revision
        //on the Travel Ticket
        UpdateTravelChange.findTravelDetail(travel_details);
        updateTravelDetailStatus.updateTravelTicket(travel_details);

//TravelCalendarUpdate.TravelDetail(travel_details);

    }
    If(Trigger.Isbefore){
        //Updates the Change Revision and Change Date Fields
        // on the Travel Detail Record
        TravelDetailBooked.updateBooked(travel_details);
    }
}
Hello, I'm trying to deploy an apex class to production but I can't because it gives me 72% of coverage code.
This is my apex class;
Does anyone know how to test this apex class and increase the coverage code? I really will appreciate any help

public with sharing class FacturaPDFController {

    public final Factura__c fct;
    public cFactura cfct{get; set;}
    public OT__c ots{get; set;}
    public xOT otts {get; set;}
    public Integer total{get; set;}
    public List<cOT> cOTList{get;set;}
    public List<cLdd> cLddList{get;set;}

    public FacturaPDFController(ApexPages.StandardController controller) {
        this.fct =  [Select Id, Pre_Factura__r.ST_Exentas__c, Pre_Factura__r.Descuento__c, Pre_Factura__r.ST_Gravadas_IVA10__c,                         Pre_Factura__r.Total_a_Pagar__c, Pre_Factura__r.IVA_10__c From Factura__c  Where Id = :controller.getId()];
        this.cfct = new cFactura(this.fct);
        total = Integer.valueOf( this.fct.Pre_Factura__r.Total_a_Pagar__c );



        //OT personalizado
        this.ots= [Select Cant_1__c,Cant_2__c,Cant_3__c,Cant_4__c,Cant_5__c, Texto_1_fact__c,Texto_2_fact__c,Texto_3_fact__c,
        Texto_4_fact__c,Texto_5_fact__c, Precio_Unit_1__c, Precio_Unit_2__c, Precio_Unit_3__c, Precio_Unit_4__c, Precio_Unit_5__c,
        Total_Ex_1__c, Total_Ex_2__c, Total_Ex_3__c, Total_Ex_4__c, Total_Ex_5__c,
        Total_Gra_1__c, Total_Gra_2__c, Total_Gra_3__c, Total_Gra_4__c, Total_Gra_5__c        
        from OT__c  where Pre_Factura__c = :this.fct.Pre_Factura__r.id];
        this.otts=new xOT(this.ots);
        
        
        
        //OT List
        this.cOTList = new List<cOT>();
        for(OT__c o : [Select Id, Codigo_2__c, Cantidad_2__c, Descripcion_2__c, Sub_Total__c, Exentas_2__c, Gravadas_IVA_10_2__c
        from OT__c  where Pre_Factura__c = :this.fct.Pre_Factura__r.id LIMIT 10]){
            cOTList.add(new cOT(o));
        }

        //LDD List
        this.cLddList = new List<cLdd>();
        for(Linea_de_detalle__c l : [Select Q__c, P_Unit_Linea__c, Total_Exentas__c, Total_Gravadas_IVA_10__c, Producto__r.Codigo__c,                   Producto__r.Descripcion__c from Linea_de_detalle__c Where OT__r.Pre_Factura__c = :this.fct.Pre_Factura__r.id LIMIT 10]){
            cLddList.add(new cLdd(l));
        }
    }



    public String getNumberToWords(){
        return NumberToSpanishWords.toSpanishWords( total );
    }


    public class cFactura{
        public Factura__c fct{get; set;}
        public String ST_Exentas{get;set;}
        public String ST_Gravadas_IVA10{get;set;}
        public String Total_a_Pagar{get;set;}
        public String IVA_10{get;set;}
        public String Descuento{get;set;}

        public cFactura(Factura__c f){
            this.fct = f;
            this.ST_Exentas = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.ST_Exentas__c);
            this.ST_Gravadas_IVA10 = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.ST_Gravadas_IVA10__c);
            this.Total_a_Pagar = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.Total_a_Pagar__c);
            this.IVA_10 = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.IVA_10__c);
            this.Descuento = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.Descuento__c);
        }
    }
    
    
    public class xOT{ //valores que se usa para la OT personalizada
        public OT__c ots{get; set;}
        public string cantper1 {get; set;}
        public string cantper2 {get; set;}
        public string cantper3 {get; set;}
        public string cantper4 {get; set;}
        public string cantper5 {get; set;}
        public string precio1 {get; set;}
        public string precio2 {get; set;}
        public string precio3 {get; set;}
        public string precio4 {get; set;}
        public string precio5 {get; set;}
        public string totalexenta1 {get; set;}
        public string totalexenta2 {get; set;}
        public string totalexenta3 {get; set;}
        public string totalexenta4 {get; set;}
        public string totalexenta5 {get; set;}
        public string totalgravada1 {get; set;}
        public string totalgravada2 {get; set;}
        public string totalgravada3 {get; set;}
        public string totalgravada4 {get; set;}
        public string totalgravada5 {get; set;}
        
        
        public xOT(OT__c ot2) {
            this.ots=ot2;
            this.cantper1= NumberToSpanishWords.convertToEU(ot2.Cant_1__c);            
            this.cantper2= NumberToSpanishWords.convertToEU(ot2.Cant_2__c);
            this.cantper3= NumberToSpanishWords.convertToEU(ot2.Cant_3__c);
            this.cantper4= NumberToSpanishWords.convertToEU(ot2.Cant_4__c);
            this.cantper5= NumberToSpanishWords.convertToEU(ot2.Cant_5__c);
            this.precio1=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_1__c);
            this.precio2=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_2__c);
            this.precio3=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_3__c);
            this.precio4=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_4__c);
            this.precio5=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_5__c);
            this.totalexenta1=NumberToSpanishWords.convertToEU(ot2.Total_Ex_1__c);
            this.totalexenta2=NumberToSpanishWords.convertToEU(ot2.Total_Ex_2__c);
            this.totalexenta3=NumberToSpanishWords.convertToEU(ot2.Total_Ex_3__c);
            this.totalexenta4=NumberToSpanishWords.convertToEU(ot2.Total_Ex_4__c);
            this.totalexenta5=NumberToSpanishWords.convertToEU(ot2.Total_Ex_5__c);
            this.totalgravada1=NumberToSpanishWords.convertToEU(ot2.Total_Gra_1__c);
            this.totalgravada2=NumberToSpanishWords.convertToEU(ot2.Total_Gra_2__c);
            this.totalgravada3=NumberToSpanishWords.convertToEU(ot2.Total_Gra_3__c);
            this.totalgravada4=NumberToSpanishWords.convertToEU(ot2.Total_Gra_4__c);
            this.totalgravada5=NumberToSpanishWords.convertToEU(ot2.Total_Gra_5__c);
     }
     
    }       
            
    public class cOT{ //valores que se usa para cuando la Pre_Factura tiene mas de una OT
        public OT__c OT{get; set;}
        public String Sub_Total{get;set;}
        public String Exentas_2{get;set;}
        public String Gravadas_IVA_10_2{get;set;}

        public cOT(OT__c o){
            this.OT = o;
            this.Sub_Total = NumberToSpanishWords.convertToEU(o.Sub_Total__c);
            this.Exentas_2 = NumberToSpanishWords.convertToEU(o.Exentas_2__c);
            this.Gravadas_IVA_10_2 = NumberToSpanishWords.convertToEU(o.Gravadas_IVA_10_2__c);
            
        } 
    }

    public class cLdd{
        public Linea_de_detalle__c LDD{get; set;}
        public String P_Unit_Linea{get;set;}
        public String Total_Exentas{get;set;}
        public String Total_Gravadas_IVA_10{get;set;}

        public cLdd(Linea_de_detalle__c l){
            this.LDD = l;
            this.P_Unit_Linea = NumberToSpanishWords.convertToEU(l.P_Unit_Linea__c);
            this.Total_Exentas = NumberToSpanishWords.convertToEU(l.Total_Exentas__c);
            this.Total_Gravadas_IVA_10 = NumberToSpanishWords.convertToEU(l.Total_Gravadas_IVA_10__c);
        }
    }
}


this is the test that I diid but it gives me this error:
FacturaPDFControllerTest.testFacturaPDFController(), Details, System.QueryException: List has no rows for assigment to sObject Class.FacturaPDFController <ini>: line 21 column 1
Class.FacturaPDFControllerTest.testFacturaPDFController:line 22, column 1

@isTest
public class FacturaPDFControllerTest {
   public static testMethod void testFacturaPDFController() {
         Pre_Factura__c prefactura = new Pre_Factura__c ();
         insert prefactura;
       
         Factura__c fac = new Factura__c(Pre_Factura__c = prefactura.id);
          /*Write code to populate fields. See my note below*/ 
            fac.Pre_impreso__c=1234999;
            fac.Pre_impreso_001_001__c=1234999;
            fac.Pre_impreso_002_001__c=1234999;
            fac.Pre_impreso_002_002__c=1234999;
            fac.Pre_impreso_003_001__c=1234999;
            fac.Caja__c='Caja 1';
            fac.Serie__c='Serie 1';
            fac.Sucursal__c='Maker Villa Morra';
                
            insert fac;
 
   
         ApexPages.StandardController fact = new ApexPages.StandardController(fac);       
         FacturaPDFController facts = new FacturaPDFController(fact);
         facts.total=1000;
         facts.getNumberToWords();
         System.assert(facts.fct  <> NULL);

      }
  }
Hello, I'm trying to deploy an apex class to production but I can't because it gives me 72% of coverage code.
This is my apex class;
Does anyone know how to test this apex class? I really will appreciate any help

public with sharing class FacturaPDFController {

    private final Factura__c fct;
    public cFactura cfct{get; set;}
    public OT__c ots{get; set;}
    public xOT otts {get; set;}
    public Integer total{get; set;}
    public List<cOT> cOTList{get;set;}
    public List<cLdd> cLddList{get;set;}

    public FacturaPDFController(ApexPages.StandardController controller) {
        this.fct =  [Select Id, Pre_Factura__r.ST_Exentas__c, Pre_Factura__r.Descuento__c, Pre_Factura__r.ST_Gravadas_IVA10__c,                         Pre_Factura__r.Total_a_Pagar__c, Pre_Factura__r.IVA_10__c From Factura__c  Where Id = :controller.getId()];
        this.cfct = new cFactura(this.fct);
        total = Integer.valueOf( this.fct.Pre_Factura__r.Total_a_Pagar__c );



        //OT personalizado
        this.ots= [Select Cant_1__c,Cant_2__c,Cant_3__c,Cant_4__c,Cant_5__c, Texto_1_fact__c,Texto_2_fact__c,Texto_3_fact__c,
        Texto_4_fact__c,Texto_5_fact__c, Precio_Unit_1__c, Precio_Unit_2__c, Precio_Unit_3__c, Precio_Unit_4__c, Precio_Unit_5__c,
        Total_Ex_1__c, Total_Ex_2__c, Total_Ex_3__c, Total_Ex_4__c, Total_Ex_5__c,
        Total_Gra_1__c, Total_Gra_2__c, Total_Gra_3__c, Total_Gra_4__c, Total_Gra_5__c        
        from OT__c  where Pre_Factura__c = :this.fct.Pre_Factura__r.id];
        this.otts=new xOT(this.ots);
        
        
        
        //OT List
        this.cOTList = new List<cOT>();
        for(OT__c o : [Select Id, Codigo_2__c, Cantidad_2__c, Descripcion_2__c, Sub_Total__c, Exentas_2__c, Gravadas_IVA_10_2__c
        from OT__c  where Pre_Factura__c = :this.fct.Pre_Factura__r.id LIMIT 10]){
            cOTList.add(new cOT(o));
        }

        //LDD List
        this.cLddList = new List<cLdd>();
        for(Linea_de_detalle__c l : [Select Q__c, P_Unit_Linea__c, Total_Exentas__c, Total_Gravadas_IVA_10__c, Producto__r.Codigo__c,                   Producto__r.Descripcion__c from Linea_de_detalle__c Where OT__r.Pre_Factura__c = :this.fct.Pre_Factura__r.id LIMIT 10]){
            cLddList.add(new cLdd(l));
        }
    }



    public String getNumberToWords(){
        return NumberToSpanishWords.toSpanishWords( total );
    }


    public class cFactura{
        public Factura__c fct{get; set;}
        public String ST_Exentas{get;set;}
        public String ST_Gravadas_IVA10{get;set;}
        public String Total_a_Pagar{get;set;}
        public String IVA_10{get;set;}
        public String Descuento{get;set;}

        public cFactura(Factura__c f){
            this.fct = f;
            this.ST_Exentas = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.ST_Exentas__c);
            this.ST_Gravadas_IVA10 = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.ST_Gravadas_IVA10__c);
            this.Total_a_Pagar = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.Total_a_Pagar__c);
            this.IVA_10 = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.IVA_10__c);
            this.Descuento = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.Descuento__c);
        }
    }
    
    
    public class xOT{ //valores que se usa para la OT personalizada
        public OT__c ots{get; set;}
        public string cantper1 {get; set;}
        public string cantper2 {get; set;}
        public string cantper3 {get; set;}
        public string cantper4 {get; set;}
        public string cantper5 {get; set;}
        public string precio1 {get; set;}
        public string precio2 {get; set;}
        public string precio3 {get; set;}
        public string precio4 {get; set;}
        public string precio5 {get; set;}
        public string totalexenta1 {get; set;}
        public string totalexenta2 {get; set;}
        public string totalexenta3 {get; set;}
        public string totalexenta4 {get; set;}
        public string totalexenta5 {get; set;}
        public string totalgravada1 {get; set;}
        public string totalgravada2 {get; set;}
        public string totalgravada3 {get; set;}
        public string totalgravada4 {get; set;}
        public string totalgravada5 {get; set;}
        
        
        public xOT(OT__c ot2) {
            this.ots=ot2;
            this.cantper1= NumberToSpanishWords.convertToEU(ot2.Cant_1__c);            
            this.cantper2= NumberToSpanishWords.convertToEU(ot2.Cant_2__c);
            this.cantper3= NumberToSpanishWords.convertToEU(ot2.Cant_3__c);
            this.cantper4= NumberToSpanishWords.convertToEU(ot2.Cant_4__c);
            this.cantper5= NumberToSpanishWords.convertToEU(ot2.Cant_5__c);
            this.precio1=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_1__c);
            this.precio2=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_2__c);
            this.precio3=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_3__c);
            this.precio4=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_4__c);
            this.precio5=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_5__c);
            this.totalexenta1=NumberToSpanishWords.convertToEU(ot2.Total_Ex_1__c);
            this.totalexenta2=NumberToSpanishWords.convertToEU(ot2.Total_Ex_2__c);
            this.totalexenta3=NumberToSpanishWords.convertToEU(ot2.Total_Ex_3__c);
            this.totalexenta4=NumberToSpanishWords.convertToEU(ot2.Total_Ex_4__c);
            this.totalexenta5=NumberToSpanishWords.convertToEU(ot2.Total_Ex_5__c);
            this.totalgravada1=NumberToSpanishWords.convertToEU(ot2.Total_Gra_1__c);
            this.totalgravada2=NumberToSpanishWords.convertToEU(ot2.Total_Gra_2__c);
            this.totalgravada3=NumberToSpanishWords.convertToEU(ot2.Total_Gra_3__c);
            this.totalgravada4=NumberToSpanishWords.convertToEU(ot2.Total_Gra_4__c);
            this.totalgravada5=NumberToSpanishWords.convertToEU(ot2.Total_Gra_5__c);
     }
     
    }       
            
    public class cOT{ //valores que se usa para cuando la Pre_Factura tiene mas de una OT
        public OT__c OT{get; set;}
        public String Sub_Total{get;set;}
        public String Exentas_2{get;set;}
        public String Gravadas_IVA_10_2{get;set;}

        public cOT(OT__c o){
            this.OT = o;
            this.Sub_Total = NumberToSpanishWords.convertToEU(o.Sub_Total__c);
            this.Exentas_2 = NumberToSpanishWords.convertToEU(o.Exentas_2__c);
            this.Gravadas_IVA_10_2 = NumberToSpanishWords.convertToEU(o.Gravadas_IVA_10_2__c);
            
        } 
    }

    public class cLdd{
        public Linea_de_detalle__c LDD{get; set;}
        public String P_Unit_Linea{get;set;}
        public String Total_Exentas{get;set;}
        public String Total_Gravadas_IVA_10{get;set;}

        public cLdd(Linea_de_detalle__c l){
            this.LDD = l;
            this.P_Unit_Linea = NumberToSpanishWords.convertToEU(l.P_Unit_Linea__c);
            this.Total_Exentas = NumberToSpanishWords.convertToEU(l.Total_Exentas__c);
            this.Total_Gravadas_IVA_10 = NumberToSpanishWords.convertToEU(l.Total_Gravadas_IVA_10__c);
        }
    }
}
I have a custom object called Questions. This object has a lookup to itself because a question can have additional questions which depend on their parent question. We need to insert 200+ at a time so I wrote an apex class that simply inserts the collection given to it:

global with sharing class QuestionRestController{
   global class RequestBody {
       global List<Question__c> questions;
   }

    @HttpPost   
    global static List<Question__c> createBulk(QuestionRestController.RequestBody req) {
        insert req.questions;
        return req.questions;
    }
}

I get this error: System.DmlException: Insert failed. First exception on row 94; first error: INVALID_FIELD, Foreign key external ID: 966.0 not found for field MyExtId__c in entity Question__c no matter what I try.

I figured I could sort the questions before sending the request so that the parent questions are always inserted first but I still get the errors. I've added debug statements so I could verify the order of the questions prior to inserting and they are ordered correctly. I've also tried to insert each question by itself:

for (Question__c question: req.questions) {
    insert question;
}

But then I get a System.LimitException because I'm sending 200+ questions.

So what is the proper way to insert a list of custom objects which have a lookup to itself when the parent and child are both being inserted with the same request?

Thanks
I'm setting up a project in Eclipse to download all of our workflow rules.  I select all for Workflow rules and I see many files in the workflows directory; Account.workflow, Opportunity.workflow, etc.  However, Contact.workflow is missing.  There's also another custom object we have that's missing.  But there are some custom objects there that don't even have any workflows.

I looked through the logs and saw some Java exceptions at the time of a metadata refresh but they didn't give me a clue as to why this would be happening.  Does anybody have any clues as to why some metadata components would be downloaded while others aren't being downloaded?

Thanks!!
I have a program that runs every morning at 4:00 am.  Since it does some CPU intensive calculations I put some of the heavy lifting into five future functions that are called from within the main program.  Things generally are working fine.

Occassionally, I'll get a message about locked rows.  This is, of course, quite bad as some of my updates just don't happen.

I did some other coding with batch files and got around this by having Batch-1 call Batch-2 which calls Batch-3, etc.  Is there some way to make sure five different future calls won't run at the same time?

Thanks!
Hello 

 I have 95% covergae in production , and I moving classes/triggers that have (97%) coverage in dev. 

Whan I deploy in production , I am getting the error 

Code Coverage Failure
Your organization's code coverage is 73%. You need at least 75% coverage to complete this deployment.

what am I missing here !?

Thanks 

Hi,

Could u please help me in the following scnearios - 

1. I have a vf page which displays list of cases with a picklist in each row and a save button. I want when i press save button it will save the record and redirect me to the same page. 

Currently i am not using any custom controller  and the save button after click is re-directing to home page.
We were upgraded to Summer '14 over the weekend.  Now I have tests that are failing that haven't failed in months.  The issue is that I'm running several versions of a batch process to catch various parts of the code.  It's now complaining that I'm running more than 5 batch processes on our network and that's why the test is failing.

I checked and the test code on production hasn't been changed since February but just started failing this week.

Any ideas?  Thanks!!
Hi !

I have a simple test method which creates an Account and a Contact. A trigger on Contact which sets a field based on the Account's BillingState. Problem is when the trigger fires the Billing state evelautes to null. I cannot understand as to why. Here is test method setting these up.

test method:

static testMethod void validate() {
     
        Test.startTest();
         
        account[] accounts = new account[]{
        new account(name='highschool',BillingState='CA',BillingPostalCode='92100') };
 
        insert accounts;

        contact[] contacts = new contact[] {
        new contact(LastName='Sand10',TargetX_SRMb__Student_Type__c='New Freshman',accountId=accounts[0].id)};
 
        insert contacts;
        Test.stopTest();

        List<contact> con = [select id, LastName, FirstName,TargetX_SRMb__Student_Type__c,TargetX_SRMb__College__c,account.BillingState, account.billingPostalCode,Territory_Assignments__c from Contact];
         
        for(Contact e: con) {
    
        System.debug('Last name.......... '+e.lastname+'  State '+e.account.BillingState);   // this actually DOES return BillingState
}

In trigger logic:

...
if(String.isNotBlank(c.TargetX_SRMb__Student_Type__c) ){ 
     system.debug('lastname in trigger: '+c.lastname+' state is '+c.account.billingState);    // this shows null for BillingState
        //look at territory state
        if(String.isNotBlank(c.Account.BillingState)){
              system.debug('not blank');                                    // never get here
.....    
Thanks,
Jon