• Lori Buchowicz
  • NEWBIE
  • 10 Points
  • Member since 2020
  • IT Specialist
  • Hinsdale Humane Society

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Schedule returning error message - assistance needed please:
*/
@isTest
public class NightlyDepositBatchTest {
public static String CRON_EXP = '0 0 0 15 3 ? 2022';
@testSetup
static void setup() {
List donations = new List();
for (Integer i=0;i donList = [SELECT Id, Donation_Use__c, Tributee__c, Gift_Type__c, Amount__c, GL_Code__c FROM Donations__c];
for(Donations__c donation: donList){
Test.setCreatedDate(donation.id, Datetime.newInstance(date.today(), Time.newInstance(0,0,0,0)).addDays(-1));
}
update donList;

}
@isTest static void test() {
Test.startTest();
NightlyDepositBatch uca = new NightlyDepositBatch(Date.today());
Id batchId = Database.executeBatch(uca);
Test.stopTest();
// after the testing stops, assert records were created properly
List depositLines = [SELECT Id,SUM(Amount__c) FROM QB_Deposit_Line__c GROUP BY Id LIMIT 1];
System.assertEquals(100, (Decimal)depositLines[0].get('expr0'));
}
@isTest static void test2() {
Test.startTest();
String jobId = System.schedule('ScheduledApexTest',
CRON_EXP,
new NightlyDepositSchedule());
Test.stopTest();
}
}
Unit test now returning error when deploying new test cases for other development being done and this test case not firing the scheduled test job. I have been searching for how to fix the test case and am not finding how to best resolve in the sandbox to update this and get any coverage listed for the Nightly Batch Schedule job in production.

With this above issue not able to get code coverage on this job -
global class NightlyDepositSchedule implements Schedulable{

global void execute(SchedulableContext sc) {
NightlyDepositBatch n1 = new NightlyDepositBatch(Date.today());
ID batchprocessid = Database.executeBatch(n1,Test.isRunningTest() ? 3 : 1);
}
}
Hi,
I have been working with Salesforce for a couple years but this is the first time I have needed to write an Apex Test Class and running into issues everywhere, I have started, scrapped code, restarted, and have kept running into issues.  What we are creating is an Adoption Contract from a Custom Object.  Let's start with the Apex Code for this.  This has two lookups - Account (Standard Object) and Animal (Custom Object) Master-Detail(Animal) from Animal Disposition  -
Apex:
public with sharing class AdoptionContract {
    public String dispositionId {get;set;}
    public Animal_Disposition__c disposition {get;set;}
    public String userType {get;set;}
    public String now {get;set;}

    
    public AdoptionContract () {
        dispositionId = ApexPages.currentPage().getParameters().get('dispositionId');
        userType = UserInfo.getUserType();
        now = Datetime.now().format();
        disposition = [SELECT Id, Date_of_Transfer_Intake__c, To__c, BillingStreet_Account__c, Billing_City_State_Zip__c, To_Email__c, To_Phone__c, Animal_Name__c, Calculated_Age__c, Animal_Breed__c, Microchip_Number__c, HHS_Animal__c FROM Animal_Disposition__c WHERE Id=:dispositionId];
        // TODO - order disposition records somehow?
    }
}

Visualforce page:
<apex:page controller="AdoptionContract" renderAs="pdf" showHeader="false" applyHtmlTag="false">
    <head>
        <style>
            body {
                font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
                font-size: 12px;
            }
                h {
                text-align: center;
                font-size: 18px;
                background-color: maroon;
                color: white;
                width: 100%;
            }
            h2 {
                padding-top: 0;
                margin-top: 0;
                padding-bottom: 2px;
                margin-bottom: 0;
                font-weight: 200;
                font-size: 16px;
                color: maroon;
                width: 100%;
            }
            h1 {
                padding-top: 0;
                margin-top: 0;
                padding-bottom: 2px;
                margin-bottom: 0;
                font-weight: 200;
                font-size: 16px;
            }
            p {
                margin: 0;
                padding: 0;
            }
            .tableHeader {
                background-color: #F9F9F7;
                padding: 10px;
                margin-bottom: 10px; 
            }
            .animalTable {
                margin-bottom: 5px;
                width: 100%
            }
            
            .icon {
                margin-bottom: 25px;
            }
            
            table {
                border-collapse: collapse;
            }
            table, th, td {
                padding-left: 5px;
                padding-right: 5px;
            }
            th {
                font-weight: 400;
                font-size: 14px;
            }
            
            .tableAndHeader {
                page-break-inside: avoid;
            }
            
            @page {
                margin: 0.5in;
                @bottom-right {
                    content: "Page " counter(page) " of " counter(pages);
                }
            }
        </style>
    </head>
    <body>
        <apex:image styleClass="icon" url="{!IF(userType='Standard', $Resource.HHSMEDSUM , $Resource.EleosLogo)}" width="300" height="{!IF(userType='Standard', 110, 'auto')}"/>
        <apex:pageBlock >
        <apex:pageBlockSection collapsible="false" columns="2"> 
                <apex:outputField label="Adopter: " value="{!disposition.To__c}"/>
                <apex:outputField label="Pet Name: " value="{!disposition.Animal_Name__c}"/>  
                <apex:outputField label="Address: " value="{!disposition.BillingStreet_Account__c}"/>
                <apex:outputField label="Breed: " value="{!disposition.Animal_Breed__c}"/>
                <apex:outputField label="City,State,Zip: " value="{!disposition.Billing_City_State_Zip__c}"/>
                <apex:outputField label="Age: " value="{!disposition.Calculated_Age__c}"/>
                <apex:outputField label="Phone: " value="{!disposition.To_Phone__c}"/>
                <apex:outputField label="Microchip: " value="{!disposition.Microchip_Number__c}"/>
                <apex:outputField label="Email: " value="{!disposition.To_Email__c}"/>
                <apex:outputField label="HHS Tag: " value="{!disposition.HHS_Animal__c}"/>
    </apex:pageBlockSection>
    </apex:pageBlock>
        <br/>
            <div class="tableAndHeader">
            <div class="tableHeader">
                <h1>ADOPTION CONTRACT</h1>
                </div>
        <br/>
        <br/>
        I agree that my continued ownership of the above-described animal is subject to the following conditions: <br/>
        <br/>
1. I am 21 years of age or older and I am adopting this animal as my own companion animal.  I will not give it as a <br/>
 &nbsp; gift, resell it, or use it for breeding and/or experimental purposes.
        <br/>
        <br/>
 <br/>
Please sign ____________________________________ <br/>
         <br/>
Printed name _________________________________  <br/>
         <br/>
/* Removed majority of text so you can see what we are trying to accomplish.
Date_______________  <br/>
         <br/>
Staff Initials ________  <br/>

</div>  
</body>
</apex:page>


This looks great in the Sandbox but to write a test case for the Lookup's and get the values to read in is proving difficult.  I have scrapped/saved to a text file all my attempts but too many errors to tackle.   I appreicate any direction to yield a clean test case to deploy this to production.  Thank you!
Schedule returning error message - assistance needed please:
*/
@isTest
public class NightlyDepositBatchTest {
public static String CRON_EXP = '0 0 0 15 3 ? 2022';
@testSetup
static void setup() {
List donations = new List();
for (Integer i=0;i donList = [SELECT Id, Donation_Use__c, Tributee__c, Gift_Type__c, Amount__c, GL_Code__c FROM Donations__c];
for(Donations__c donation: donList){
Test.setCreatedDate(donation.id, Datetime.newInstance(date.today(), Time.newInstance(0,0,0,0)).addDays(-1));
}
update donList;

}
@isTest static void test() {
Test.startTest();
NightlyDepositBatch uca = new NightlyDepositBatch(Date.today());
Id batchId = Database.executeBatch(uca);
Test.stopTest();
// after the testing stops, assert records were created properly
List depositLines = [SELECT Id,SUM(Amount__c) FROM QB_Deposit_Line__c GROUP BY Id LIMIT 1];
System.assertEquals(100, (Decimal)depositLines[0].get('expr0'));
}
@isTest static void test2() {
Test.startTest();
String jobId = System.schedule('ScheduledApexTest',
CRON_EXP,
new NightlyDepositSchedule());
Test.stopTest();
}
}
Unit test now returning error when deploying new test cases for other development being done and this test case not firing the scheduled test job. I have been searching for how to fix the test case and am not finding how to best resolve in the sandbox to update this and get any coverage listed for the Nightly Batch Schedule job in production.

With this above issue not able to get code coverage on this job -
global class NightlyDepositSchedule implements Schedulable{

global void execute(SchedulableContext sc) {
NightlyDepositBatch n1 = new NightlyDepositBatch(Date.today());
ID batchprocessid = Database.executeBatch(n1,Test.isRunningTest() ? 3 : 1);
}
}
How do I relate a standardcontroller to a custom object on a visual force page 
<apex:page standardController="ts2__Placement__c"  showHeader="false" sidebar="false">
  <p>You are viewing the {!ts2__Placement__c.name} record .</p>
Sample Encrypted Bank Account:  <apex:outputField value="{!ts2__Placement__c.Sample_Bank_Acc__c}" /><br />
</apex:page>

I am getting a error saying I cannot use the custom object on the visualforce page when I try to do this.