• Jean-Se Dorais
  • NEWBIE
  • 20 Points
  • Member since 2020
  • CEO
  • 21 Knots


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hello all,

I've got a 'FundingAwardTrigger' on the FundingAward object (part of the Grantmaking package).  When I run the test in Sandbox, I get 100% coverage.

When I validate the Inbound Change Set in Prod, I get the following error:

Code Coverage Failure
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
FundingAwardTrigger

Here's my test class:
 
@isTest
private class FundingAwardTriggerTest {

    @isTest static void testTriggerOnInsert() {
        // Create a test record for the insert operation
        FundingAward testAwardInsert = new FundingAward(Name = 'Test Insert', Amount = 100);

        // Start the test context
        Test.startTest();

        // Perform the insert operation
        insert testAwardInsert;

        // Stop the test context
        Test.stopTest();

        // Retrieve the inserted record and assert the result
        testAwardInsert = [SELECT Currency_Text__c FROM FundingAward WHERE Id = :testAwardInsert.Id];
        System.assertEquals('One Hundred', testAwardInsert.Currency_Text__c, 'Trigger did not work as expected on insert');
    }

    @isTest static void testTriggerOnUpdate() {
        // Create and insert a record for the update operation
        FundingAward testAwardUpdate = new FundingAward(Name = 'Test Update', Amount = 100);
        insert testAwardUpdate;

        // Start the test context
        Test.startTest();

        // Perform the update operation
        testAwardUpdate.Amount = 200;
        update testAwardUpdate;

        // Stop the test context
        Test.stopTest();

        // Retrieve the updated record and assert the result
        testAwardUpdate = [SELECT Currency_Text__c FROM FundingAward WHERE Id = :testAwardUpdate.Id];
        System.assertEquals('Two Hundred', testAwardUpdate.Currency_Text__c, 'Trigger did not work as expected on update');
    }

 		@isTest static void testBulkOperation() {
        // Create multiple records for testing bulk operation
        List<FundingAward> awards = new List<FundingAward>();
        for (Integer i = 1; i <= 10; i++) {
            awards.add(new FundingAward(Name = 'Bulk Test Award ' + i, Amount = i * 100));
        }

        // Start the test context
        Test.startTest();

        // Perform bulk insert
        insert awards;

        // Update the records for bulk update test
        for (Integer i = 0; i < awards.size(); i++) {
            awards[i].Amount += 1000;
        }

        // Perform bulk update
        update awards;

        // Stop the test context
        Test.stopTest();

        // Optional: Add assertions here to validate the trigger's behavior on bulk operations
    }

}
Why would my test class show 100% in sandbox but 0% in prod?

Any tips appreciated!
 
Hello all,

I have 1 Apex Class in a change set.  Everything works in Sandbox env. but when I try to bring the Class into Prod via an inbound change set, I get: 

Code Coverage Failure
Your code coverage is 69%. You need at least 75% coverage to complete this deployment.


Here is my Apex Class
public class CurrentRecordIdController{
public String currentRecordId {get;set;}
public String parameterValue {get;set;}
public Lead lead{get;set;}

public String data {get;set;}
public Blob mac {get;set;}
public String sig {get;set;}
public String url {get;set;}
 
    public CurrentRecordIdController(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        lead = [Select Id, Name, Email, Company from Lead where Id =: currentRecordId ];
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');

        data = currentRecordId;
        mac = Crypto.generateMac('HMacSHA256', Blob.valueOf(data), Blob.valueOf('kay'));
        sig = EncodingUtil.urlEncode(EncodingUtil.base64Encode(mac), 'UTF-8');
        url = 'https://mysite.com/123456?lid=' + currentRecordId + '&signature=' + sig;

}

}

Any tips on how to get past this issue? I read somewhere that I need a test class in my code but I do not know how to do that.

Thank you!
Hello,

I've pieced together some code and at a step where I need a little help.

I've got the following class that retrieves the current Lead Id (this will be launched via a button on the lead object):
public class CurrentRecordIdDemoController{
public String currentRecordId {get;set;}
public String parameterValue {get;set;}
public Lead lead{get;set;}
 
    public CurrentRecordIdDemoController(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        lead = [Select Id, Name, Email, Company from Lead where Id =: currentRecordId ];
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
    }
}
...and the following VF page:
<apex:page standardController="Lead" extensions="CurrentRecordIdDemoController">

String data = {!currentRecordId};
Blob mac = Crypto.generateMac('HMacSHA256', Blob.valueOf(data), Blob.valueOf('ABC123'));
String sig = EncodingUtil.urlEncode(EncodingUtil.base64Encode(mac), 'UTF-8');
String url = 'https://mysite.com/4945922?lid={!currentRecordId}&amp;signature=' + sig;

  <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection title="Current lead record Id is : {!currentRecordId}" collapsible="false">
            <apex:outputField value="{!lead.Name}"/>
            <apex:outputField value="{!lead.Email}"/>
            <apex:outputField value="{!lead.Company}"/>
        </apex:pageBlockSection>

         
    </apex:pageBlock>
  </apex:form>
</apex:page>
I would like the String url to be displayed in the <apex:form> section but unsure how to do so.

The code above <apex:form> needs to be reformated as I'm currently getting the following output:

Current output
How would one reformat the Visualforce page code to achieve this?

Thank you!

 
Hi all,

Newbie here.

I've got the following VF code that generates a Word doc when an action button is pressed on a custom object (Contract_Work_Order__c).

I'm trying to retrieve a contact's full name based on its id.  The field below is returning the Contact ID.  

{!Contract_Work_Order__c.Contractor__c}

I essentially need to write the following select statement and return the value.
Select name from contacts where Id ={!Contract_Work_Order__c.Contractor__c}

Here's the current VF page:
 
<apex:page standardController="Contract_Work_Order__c" contentType="application/msword#MSA_{!Contract_Work_Order__c.Id}.doc" sidebar="false" standardStylesheets="false" applyBodyTag="false">

<div style="font-family:sans-serif;"> 
<center>
<h4>MASTER SUB-CONSULTANT AGREEMENT</h4>
</center>
</div>
 
<div style="font-family:sans-serif;text-align:left;font-size:10pt;">
<p>This MASTER SUB-CONSULTANT AGREEMENT ("Agreement") is made and entered into as of <apex:outputText value=" {!TODAY()}"/> (“Effective Date”), 
by and between XYZ, and <apex:outputText value=" {!Contract_Work_Order__c.Contractor__c}"/> ("Sub-Consultant”), each individually sometimes referred to as a “Party” and collectively as “Parties”.</p>
 
<p>Your account details are:</p>
 
<table>
<tr><th>Opportunity Name</th>
    <td><apex:outputText value="{!Contract_Work_Order__c.Opportunity__c}"/></td>
    </tr>
<tr><th>Account Rep</th>
    <td><apex:outputText value="{!Contract_Work_Order__c.Account_Rep__c}"/></td>
    </tr>
<tr><th>Customer Since</th>
    <td><apex:outputText value="{0,date,long}">
        <apex:param value="{!Contract_Work_Order__c.CreatedDate}"/>
        </apex:outputText></td>
    </tr>
</table>
    
<p>It's a pleasure to have you on board.  Please do not hesitate to contact us should you have any questions or concerns.</p>
    
<p>Sincerely,</p>
    
<p><apex:outputText value="{!Contract_Work_Order__c.CreatedById}"/></p>
</div>
    
</apex:page>

I'm stuck and would appreciate your pointers!

Thank you.

 
Hello all,

I've got a 'FundingAwardTrigger' on the FundingAward object (part of the Grantmaking package).  When I run the test in Sandbox, I get 100% coverage.

When I validate the Inbound Change Set in Prod, I get the following error:

Code Coverage Failure
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
FundingAwardTrigger

Here's my test class:
 
@isTest
private class FundingAwardTriggerTest {

    @isTest static void testTriggerOnInsert() {
        // Create a test record for the insert operation
        FundingAward testAwardInsert = new FundingAward(Name = 'Test Insert', Amount = 100);

        // Start the test context
        Test.startTest();

        // Perform the insert operation
        insert testAwardInsert;

        // Stop the test context
        Test.stopTest();

        // Retrieve the inserted record and assert the result
        testAwardInsert = [SELECT Currency_Text__c FROM FundingAward WHERE Id = :testAwardInsert.Id];
        System.assertEquals('One Hundred', testAwardInsert.Currency_Text__c, 'Trigger did not work as expected on insert');
    }

    @isTest static void testTriggerOnUpdate() {
        // Create and insert a record for the update operation
        FundingAward testAwardUpdate = new FundingAward(Name = 'Test Update', Amount = 100);
        insert testAwardUpdate;

        // Start the test context
        Test.startTest();

        // Perform the update operation
        testAwardUpdate.Amount = 200;
        update testAwardUpdate;

        // Stop the test context
        Test.stopTest();

        // Retrieve the updated record and assert the result
        testAwardUpdate = [SELECT Currency_Text__c FROM FundingAward WHERE Id = :testAwardUpdate.Id];
        System.assertEquals('Two Hundred', testAwardUpdate.Currency_Text__c, 'Trigger did not work as expected on update');
    }

 		@isTest static void testBulkOperation() {
        // Create multiple records for testing bulk operation
        List<FundingAward> awards = new List<FundingAward>();
        for (Integer i = 1; i <= 10; i++) {
            awards.add(new FundingAward(Name = 'Bulk Test Award ' + i, Amount = i * 100));
        }

        // Start the test context
        Test.startTest();

        // Perform bulk insert
        insert awards;

        // Update the records for bulk update test
        for (Integer i = 0; i < awards.size(); i++) {
            awards[i].Amount += 1000;
        }

        // Perform bulk update
        update awards;

        // Stop the test context
        Test.stopTest();

        // Optional: Add assertions here to validate the trigger's behavior on bulk operations
    }

}
Why would my test class show 100% in sandbox but 0% in prod?

Any tips appreciated!
 
Hi all,

Newbie here.

I've got the following VF code that generates a Word doc when an action button is pressed on a custom object (Contract_Work_Order__c).

I'm trying to retrieve a contact's full name based on its id.  The field below is returning the Contact ID.  

{!Contract_Work_Order__c.Contractor__c}

I essentially need to write the following select statement and return the value.
Select name from contacts where Id ={!Contract_Work_Order__c.Contractor__c}

Here's the current VF page:
 
<apex:page standardController="Contract_Work_Order__c" contentType="application/msword#MSA_{!Contract_Work_Order__c.Id}.doc" sidebar="false" standardStylesheets="false" applyBodyTag="false">

<div style="font-family:sans-serif;"> 
<center>
<h4>MASTER SUB-CONSULTANT AGREEMENT</h4>
</center>
</div>
 
<div style="font-family:sans-serif;text-align:left;font-size:10pt;">
<p>This MASTER SUB-CONSULTANT AGREEMENT ("Agreement") is made and entered into as of <apex:outputText value=" {!TODAY()}"/> (“Effective Date”), 
by and between XYZ, and <apex:outputText value=" {!Contract_Work_Order__c.Contractor__c}"/> ("Sub-Consultant”), each individually sometimes referred to as a “Party” and collectively as “Parties”.</p>
 
<p>Your account details are:</p>
 
<table>
<tr><th>Opportunity Name</th>
    <td><apex:outputText value="{!Contract_Work_Order__c.Opportunity__c}"/></td>
    </tr>
<tr><th>Account Rep</th>
    <td><apex:outputText value="{!Contract_Work_Order__c.Account_Rep__c}"/></td>
    </tr>
<tr><th>Customer Since</th>
    <td><apex:outputText value="{0,date,long}">
        <apex:param value="{!Contract_Work_Order__c.CreatedDate}"/>
        </apex:outputText></td>
    </tr>
</table>
    
<p>It's a pleasure to have you on board.  Please do not hesitate to contact us should you have any questions or concerns.</p>
    
<p>Sincerely,</p>
    
<p><apex:outputText value="{!Contract_Work_Order__c.CreatedById}"/></p>
</div>
    
</apex:page>

I'm stuck and would appreciate your pointers!

Thank you.