• Upton_X
  • NEWBIE
  • 35 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies

I keep getting this error.  Why?

 

List<Case> userCreatedCases = [SELECT Id, CreatedById FROM Case WHERE CreatedDated = 2005-10-08T01:02:03Z];
Hello - I have been able to find how to calculate the first day of the month with a DateTime method, however I am struggling with DateTime for last day of month and have not been able to find anything online.

I need datetime specifically because I can only query Case.CreatedDate with that datatype.

Line 8 Specifically
trigger ScratchTrigger on Case (before insert) {
//Write a trigger that will prevent each user from creating more than 99 cases a month
    
    //Create values for this month
    Date dayToday = Date.Today();
    DateTime firstDayOfMonth = DateTime.newInstance(daytoday.toStartOfMonth().addMonths(-1), Time.newInstance(0,0,0,0));
    
    DateTime lastDayOfMonth  = DateTime.newInstance(dayToday.addMonths(1).toStartofMonth().addDays(-1)), Time.newInstance(0,0,0,0));
        
    
    system.debug('Todays Date = '+dayToday+ ' firstDayOfMonth = '+firstDayOfMonth+ ' lastday of Month = '+lastDayOfMonth);
    
    //When a new case is crated, iterate through Trigger.New and add case to UserCreated Cases
    if(Trigger.isInsert){
    List<Case> UserCreatedCases = [SELECT Id, CreatedById, CreatedDate FROM Case WHERE (CreatedDated >= :firstDayOfMonth) AND (CreatedDate <= :lastDayOfMonth)];
    }
    
}

 
My organization uses Conga to manage contracts. These contracts can have up to 5 related “Legal Entities”, and we have five Legal Entity lookup fields on the Contract Agreement object. Ideally we would use a junction object, but I was overruled. Now I am trying to write APEX that combines all related agreements on the Legal Entity record page, regardless which legal entity field they are related to, and display it on a visual force page.


I’ve stumbled through writing the controller and visualforce page.

However, I am having trouble with achieving 75% code coverage with a test .


Here is my class
public class CombineContractAgreement {
    Id LegalEntityId;
public CombineContractAgreement(ApexPages.StandardController controller){
    LegalEntityId = ((SB_Legal_Entity__c)controller.getRecord()).Id;
    }

    public List<APXT_Redlining__Contract_Agreement__c>GetAllRelatedAgreement()
    {
     List <APXT_Redlining__Contract_Agreement__c> AllRelatedAgreements;
        AllRelatedAgreements = [SELECT Name, Agreement_Type__C, APXT_Redlining__Status__c, APXT_Redlining__Effective_Date__c,
        Agreement_Name__c FROM APXT_Redlining__Contract_Agreement__c WHERE Customer_Legal_Entity__c = :LegalEntityId OR Customer_Legal_Entity_2__c = :LegalEntityId OR 
                                Customer_Legal_Entity_3__c = :LegalEntityId OR Party_4__c = :LegalEntityId OR Party_5__c = :LegalEntityId];
                                    return AllRelatedAgreements;
    }
}

Visualforce
<apex:page StandardController="SB_Legal_Entity__c" extensions="CombineContractAgreement" lightningStylesheets="true">
    <apex:pageBlock title="All Related Agreements">
        <apex:pageBlockTable value="{!AllRelatedAgreement}" var="item">
            <apex:column >
                <apex:outputLink value="https://hyclonehorizon--sb1.lightning.force.com/{!item.ID}">{!item.Name}</apex:outputLink>
            </apex:column>    
            <apex:column value="{!item.Agreement_Name__c}" />
            <apex:column value="{!item.Agreement_Type__c}" />
            <apex:column value="{!item.APXT_Redlining__Status__c}" />
            <apex:column value="{!item.APXT_Redlining__Effective_Date__c}" />
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Test Class
@isTest
public class CombineContractAgreementTest {
    
    static testMethod void testMethod1(){

        //Create required legal alias for Legal Entitiy Object
        Legal_Alias__c ali = new Legal_Alias__c();
        ali.Name     = 'NameLegalAlias';
        system.debug('The Legal Alias name is '+ali.Name);
        insert ali;
        

		//Create Legal Entity
        SB_Legal_Entity__c testEntity = new SB_Legal_Entity__c();
        testEntity.Legal_Alias__c = ali.Id;
        testEntity.Name     = 'testLegalEntity';
        insert testEntity;
        
        //Create Contract Agreement
        APXT_Redlining__Contract_Agreement__c testAgreement = new APXT_Redlining__Contract_Agreement__c();
        testAgreement.Customer_Legal_Entity__c          = testEntity.id;
        testAgreement.APXT_Redlining__Status__c         = 'inactive';
        testAgreement.APXT_Redlining__Effective_Date__c = date.today();
        testagreement.Agreement_Name__c                 = 'TestAgreement';
        insert testAgreement;
        System.debug('The Contract Agreements Legal Entity is' + testAgreement.Customer_Legal_Entity__c);
        
        
      Test.StartTest();
        //current page equal the legal entity page
        ApexPages.StandardController stdctrl = new ApexPages.StandardController(testEntity);
        ApexPages.currentPage().getParameters().put('id',testEntity.Id);
        CombineContractAgreement testCombineAgree = new CombineContractAgreement(stdctrl);
        stdctrl.cancel();
      Test.Stoptest();

        }


        
    }

Result:
User-added image​​​​​​​
 

Hello everyone,

Through searching various past threads it looks like this questions has been asked a few times, however I am hoping to get some specific help.

I've just last week started dedicating myself to learning to develop (SF99!)  So I understand this is beyond my range, but this is a need at my current Org, and I thought it would be fun to actually try to do some development.

Note* I understand that a junction object could be an option here.  Given the users that will be using these objects, the fewer clicks the better so I need to stick with this model.

 

We have a Contract Agreement Object that has 5 lookup fields for parties that can be related to the Contract Agreement.  On the Party Object, I have 5 list.  I would like to combine them into one list, and display them on the Party object.  Here is what I have for code so far,  I'm a newbie so I'm sure I am far off, but I'm excited to learn.

public class CombineContractAgreement {
public CombineContractAgreement(ApexPages.StandardController controller) {
    
}

   Public List <Contract_Agreement__C> AllRelatedAgreements;
    
    Public List<Contract_Agreement__c>GetAllRelatedAgreement()
    {
        AllRelatedAgreements = [SELECT id, RecordTypeId, APXT_Redlining_Status__c, APXT_Redlining__Effective_Date__c, Agreement_Name__c FROM Contract_Agreement__c 
                                
                                WHERE //Current record is value on any 1 of 5 lookup fields on the Contract Agreement Record.//
 								return AllRelatedAgreements 
                               }
 

Any help you can provide will be greatly apprchated.




 

I keep getting this error.  Why?

 

List<Case> userCreatedCases = [SELECT Id, CreatedById FROM Case WHERE CreatedDated = 2005-10-08T01:02:03Z];
Hello - I have been able to find how to calculate the first day of the month with a DateTime method, however I am struggling with DateTime for last day of month and have not been able to find anything online.

I need datetime specifically because I can only query Case.CreatedDate with that datatype.

Line 8 Specifically
trigger ScratchTrigger on Case (before insert) {
//Write a trigger that will prevent each user from creating more than 99 cases a month
    
    //Create values for this month
    Date dayToday = Date.Today();
    DateTime firstDayOfMonth = DateTime.newInstance(daytoday.toStartOfMonth().addMonths(-1), Time.newInstance(0,0,0,0));
    
    DateTime lastDayOfMonth  = DateTime.newInstance(dayToday.addMonths(1).toStartofMonth().addDays(-1)), Time.newInstance(0,0,0,0));
        
    
    system.debug('Todays Date = '+dayToday+ ' firstDayOfMonth = '+firstDayOfMonth+ ' lastday of Month = '+lastDayOfMonth);
    
    //When a new case is crated, iterate through Trigger.New and add case to UserCreated Cases
    if(Trigger.isInsert){
    List<Case> UserCreatedCases = [SELECT Id, CreatedById, CreatedDate FROM Case WHERE (CreatedDated >= :firstDayOfMonth) AND (CreatedDate <= :lastDayOfMonth)];
    }
    
}

 
My organization uses Conga to manage contracts. These contracts can have up to 5 related “Legal Entities”, and we have five Legal Entity lookup fields on the Contract Agreement object. Ideally we would use a junction object, but I was overruled. Now I am trying to write APEX that combines all related agreements on the Legal Entity record page, regardless which legal entity field they are related to, and display it on a visual force page.


I’ve stumbled through writing the controller and visualforce page.

However, I am having trouble with achieving 75% code coverage with a test .


Here is my class
public class CombineContractAgreement {
    Id LegalEntityId;
public CombineContractAgreement(ApexPages.StandardController controller){
    LegalEntityId = ((SB_Legal_Entity__c)controller.getRecord()).Id;
    }

    public List<APXT_Redlining__Contract_Agreement__c>GetAllRelatedAgreement()
    {
     List <APXT_Redlining__Contract_Agreement__c> AllRelatedAgreements;
        AllRelatedAgreements = [SELECT Name, Agreement_Type__C, APXT_Redlining__Status__c, APXT_Redlining__Effective_Date__c,
        Agreement_Name__c FROM APXT_Redlining__Contract_Agreement__c WHERE Customer_Legal_Entity__c = :LegalEntityId OR Customer_Legal_Entity_2__c = :LegalEntityId OR 
                                Customer_Legal_Entity_3__c = :LegalEntityId OR Party_4__c = :LegalEntityId OR Party_5__c = :LegalEntityId];
                                    return AllRelatedAgreements;
    }
}

Visualforce
<apex:page StandardController="SB_Legal_Entity__c" extensions="CombineContractAgreement" lightningStylesheets="true">
    <apex:pageBlock title="All Related Agreements">
        <apex:pageBlockTable value="{!AllRelatedAgreement}" var="item">
            <apex:column >
                <apex:outputLink value="https://hyclonehorizon--sb1.lightning.force.com/{!item.ID}">{!item.Name}</apex:outputLink>
            </apex:column>    
            <apex:column value="{!item.Agreement_Name__c}" />
            <apex:column value="{!item.Agreement_Type__c}" />
            <apex:column value="{!item.APXT_Redlining__Status__c}" />
            <apex:column value="{!item.APXT_Redlining__Effective_Date__c}" />
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Test Class
@isTest
public class CombineContractAgreementTest {
    
    static testMethod void testMethod1(){

        //Create required legal alias for Legal Entitiy Object
        Legal_Alias__c ali = new Legal_Alias__c();
        ali.Name     = 'NameLegalAlias';
        system.debug('The Legal Alias name is '+ali.Name);
        insert ali;
        

		//Create Legal Entity
        SB_Legal_Entity__c testEntity = new SB_Legal_Entity__c();
        testEntity.Legal_Alias__c = ali.Id;
        testEntity.Name     = 'testLegalEntity';
        insert testEntity;
        
        //Create Contract Agreement
        APXT_Redlining__Contract_Agreement__c testAgreement = new APXT_Redlining__Contract_Agreement__c();
        testAgreement.Customer_Legal_Entity__c          = testEntity.id;
        testAgreement.APXT_Redlining__Status__c         = 'inactive';
        testAgreement.APXT_Redlining__Effective_Date__c = date.today();
        testagreement.Agreement_Name__c                 = 'TestAgreement';
        insert testAgreement;
        System.debug('The Contract Agreements Legal Entity is' + testAgreement.Customer_Legal_Entity__c);
        
        
      Test.StartTest();
        //current page equal the legal entity page
        ApexPages.StandardController stdctrl = new ApexPages.StandardController(testEntity);
        ApexPages.currentPage().getParameters().put('id',testEntity.Id);
        CombineContractAgreement testCombineAgree = new CombineContractAgreement(stdctrl);
        stdctrl.cancel();
      Test.Stoptest();

        }


        
    }

Result:
User-added image​​​​​​​
 

Hello everyone,

Through searching various past threads it looks like this questions has been asked a few times, however I am hoping to get some specific help.

I've just last week started dedicating myself to learning to develop (SF99!)  So I understand this is beyond my range, but this is a need at my current Org, and I thought it would be fun to actually try to do some development.

Note* I understand that a junction object could be an option here.  Given the users that will be using these objects, the fewer clicks the better so I need to stick with this model.

 

We have a Contract Agreement Object that has 5 lookup fields for parties that can be related to the Contract Agreement.  On the Party Object, I have 5 list.  I would like to combine them into one list, and display them on the Party object.  Here is what I have for code so far,  I'm a newbie so I'm sure I am far off, but I'm excited to learn.

public class CombineContractAgreement {
public CombineContractAgreement(ApexPages.StandardController controller) {
    
}

   Public List <Contract_Agreement__C> AllRelatedAgreements;
    
    Public List<Contract_Agreement__c>GetAllRelatedAgreement()
    {
        AllRelatedAgreements = [SELECT id, RecordTypeId, APXT_Redlining_Status__c, APXT_Redlining__Effective_Date__c, Agreement_Name__c FROM Contract_Agreement__c 
                                
                                WHERE //Current record is value on any 1 of 5 lookup fields on the Contract Agreement Record.//
 								return AllRelatedAgreements 
                               }
 

Any help you can provide will be greatly apprchated.