• Tad Aalgaard 1
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi,

I have deployed this Apex Testing class in production that messed up my whole production org; it got to a point where I'm not able to deploy anything on production nor able to delete it (the Apex class that's causing the issue). 

Here what I did to delete test class:

1. I download Eclipse and insalled the Foce.com IDE.
2. Then I created Foce.com two projects; one includes all my master production org components and one includes all of my sandbox components.
3. After that I went to sandbox project and altered my class file.xml to "Deleted" and changed four of my triggers (tied to the class, not needed anymore) to "Inactive"
4. I attempted to deploy the five components (referenced above) to production in order to delete trigger and deactive class but I failed. Got this error message and coverage results:
 
*** Deployment Log ***
Result: FAILED
Date: October 17, 2017 5:35:32 PM PDT

# Deployed From:
   Project name: Inbody_replacing
   Username: mahmoud@enarahealth.com.sandbox
   Endpoint: test.salesforce.com

# Deployed To:
   Username: mahmoud@enarahealth.com
   Endpoint: login.salesforce.com

# Deploy Results:
   File Name:    classes/InsertInbodyData_TestClass.cls
   Full Name:  InsertInbodyData_TestClass
   Action:  UPDATED
   Result:  SUCCESS
   Problem: n/a

   File Name:    package.xml
   Full Name:  package.xml
   Action:  UPDATED
   Result:  SUCCESS
   Problem: n/a

   File Name:    triggers/GetInitialPBFValue.trigger
   Full Name:  GetInitialPBFValue
   Action:  NO ACTION
   Result:  SUCCESS
   Problem: n/a

   File Name:    triggers/GetInitialSMMValue.trigger
   Full Name:  GetInitialSMMValue
   Action:  NO ACTION
   Result:  SUCCESS
   Problem: n/a

   File Name:    triggers/GetLatestPBFValue.trigger
   Full Name:  GetLatestPBFValue
   Action:  NO ACTION
   Result:  SUCCESS
   Problem: n/a

   File Name:    triggers/GetLatestSMMValue.trigger
   Full Name:  GetLatestSMMValue
   Action:  NO ACTION
   Result:  SUCCESS
   Problem: n/a

# Test Results:

Run Failures:
  InsertInbodyData_TestClass.UpdateBIA System.DmlException: Update failed. First exception on row 0 with id a076100000HLRd3AAH; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
User-added image

Here is the code for Apex class (InsertInbodyData_TestClass) and one of the triggers (GetInitialPBFValue) (The triggers logic is identical across all four triggers).
 
Trigger GetInitialPBFValue on Inbody__c(after insert, after update) {
    Set<Id> accountIds = new Set<Id>();

    for (Inbody__c inbdy : trigger.new) {
        accountIds.add(inbdy.Patient__c);
    }

    //Elimnate the the accounts that don't have IDs for
    accountIds.remove(null);

    //SOQL query that returns that latest weight value 
    if (!accountIds.isEmpty()) {
        List<Account> accountsToUpdate = new List<Account>();
        for (Account account : [
            Select Id,
                (
                    SELECT Test_Date_Time__c, Percent_Body_Fat__c
                    FROM Inbody__r
                    WHERE Percent_Body_Fat__c != NULL
                    ORDER by Test_Date_Time__c asc
                    Limit 1
                )
            From Account
            Where Id in :accountIds
        ]) {
           
            //Declare a decimal variable to store latest weight value 
            Decimal IPBF = NULL;
            
            // Get(0) to return the first element in the list value
            if (!account.Inbody__r.isEmpty()) {
                IPBF = account.Inbody__r.get(0).Percent_Body_Fat__c;
            }

            accountsToUpdate.add(new Account(
                Id = account.Id,
                initial_PBF_Value__c = IPBF
               
            ));
                         
        }   
        
        Update accountsToUpdate;
        
        }
      }
GetInitialPBFValue Trigger:
@isTest(SeeAllData=true)
Private class InsertInbodyData_TestClass {

    @isTest static void InsertInbody() {
        Account accnts = new Account();
        Inbody__c BIA = new Inbody__c();
        
        RecordType rt = [SELECT ID,Name FROM RecordType WHERE SobjectType='Account' and Name='Patients' Limit 1];
        
        accnts.name = 'afagas';
        accnts.RecordTypeID = rt.id;
        
        insert accnts;
        
        BIA.Skeletal_Muscle_Mass__c = 200;
        BIA.Percent_Body_Fat__c = 160;
        BIA.Test_Date_Time__c = Date.today();
        BIA.patient__c = accnts.id;
        
        insert BIA;
               
        }
        
    @isTest static void UpdateBIA() {
        Inbody__c BIA = new Inbody__c();
        BIA.id = 'a076100000HLRd3';
        BIA.weight__c = 100;
        BIA.Test_Date_Time__c = date.today();
        BIA.patient__c = '0016100000V5qTw';
        
        update BIA;   
        
        }
     
}
This issue had became a HUGE bottleneck in my development process, any input would be greatly appreciated!