• Aaron Persich 8
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
Hello,

I am very new to triggers and code and will need some help with a test class.  I have found the below trigger on the web and added it to my sandbox.  I have tested it and it works great.  The trigger updates a "Contract Status" checkbox on the account if there is an active contract associated to it.  Additionally, it will set the checkbox to false if there are no active contracts. 

I am now trying to use a changset to push this into production but I think I need to create a test class to validate it in Prod.  I could be wrong with this assumption.  Can someone please help create a test class or guide me through the process to push this into production?
 
trigger AaronPTest on Contract (after insert, after Update) {
 
    Set<Id> setAccountId = new Set<Id>();  
 
    List<Account> lstToUpdate = new List<Account>();
 
    for(Contract rec : Trigger.New)
 
    {
 
        setAccountId.add(rec.AccountId);
 
    }
 
    List<Account> lstAccount = [SELECT Id,(SELECT Id FROM Contracts WHERE Contract_Status__c = true),Contract_Status__c FROM Account Where Id IN:setAccountId];
 
    for(Account acc : lstAccount)
 
    {
 
        if(acc.Contracts.size() > 0 && !acc.Contract_Status__c){
 
            acc.Contract_Status__c = true;
 
            lstToUpdate.add(acc);
 
        }
 
        else if(acc.Contracts.size() == 0 && acc.Contract_Status__c)
 
        {
 
            acc.Contract_Status__c = false;
 
            lstToUpdate.add(acc);
 
        }
 
    }
 
         Database.update(lstToUpdate);
}
 
 
Thanks,
 
Aaron
 
 
Hello,
 
I am very new to triggers and classes and have recently been assigned a task to populate an Account Status field on the account based on the related contract status.  I have researched this and came across another post with the same question so I have tried to mirror this. 
 
I have created a checkbox labeled Active_Contract__c on both the Account and Contract objects.  I would like the trigger to set the Active_Contract__c to true on the account if there are any related contracts where the Active_Contract__c is also set to true.  If all contracts related to the Account turns to inactive (false) then I would like to set the Active_Contract__c to false on the account.
 
I found the below trigger but I think I will need to create a Class as well.  Again, I am very new to this and any help would be much appreciated.
 
 
trigger OnAccountCreated on Contract(after insert, after Update) {

    Set<Id> setAccountId = new Set<Id>();   

    List<Account> lstToUpdate = new List<Account>();

    for(Contract rec : Trigger.New)

    {

        setAccountId.add(rec.AccountId);

    }

    List<Account> lstAccount = [SELECT Id,(SELECT Id FROM Contracts WHERE Active_Contract__c = true),Active_Contract__c FROM Account Where Id IN:setAccountId];

    for(Account acc : lstAccount)

    {

        if(acc.Contracts.size() > 0 && !acc.Active_Contract__c){

            acc.Active_Contract__c = true;

            lstToUpdate.add(acc);

        }

        else if(acc.Contracts.size() == 0 && acc.Active_Contract__c)

        {

            acc.Active_Contract__c = false;

            lstToUpdate.add(acc);

        }

    }

         Database.update(lstToUpdate);
}
 
Thanks,

Aaron
Hello,

We have the below Visualforce Markup which mass eidts the Asset records when the users select the checkboxes next to the assets.  This works perfectly but I would like to take it a step further to clone and mass edit.  How can I incorporate the clone function into this mass edit function?

<apex:page standardController="Asset" recordSetVar="unused" tabStyle="Asset"
sidebar="false">
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >
Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first. 
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}" var="a" id="table">
<apex:column headerValue="Assert Name">
<apex:inputField value="{!a.name}"/>
</apex:column>
<apex:column headerValue="Account Name">
<apex:inputField value="{!a.AccountID}"/>
</apex:column>
<apex:column headerValue="Product">
<apex:inputField value="{!a.Product2Id}"/>
</apex:column>
<apex:column headerValue="Contract">
<apex:inputField value="{!a.Contract__c}"/>
</apex:column>
<apex:column headerValue="Version">
<apex:inputField value="{!a.Version__c}"/>
</apex:column>
<apex:column headerValue="Asset Start Date">
<apex:inputField value="{!a.Asset_Start_Date__c}"/>
</apex:column>
<apex:column headerValue="Asset End Date">
<apex:inputField value="{!a.Asset_End_Date__c}"/>
</apex:column>
<apex:column headerValue="PPT ID">
<apex:inputField value="{!a.PPT_ID__c}"/>
</apex:column>
<apex:column headerValue="Quantity">
<apex:inputField value="{!a.Quantity}"/>
</apex:column>
<apex:column headerValue="Tenant Name">
<apex:inputField value="{!a.Tentant_Name__c}"/>
</apex:column>
<apex:column headerValue="Status">
<apex:inputField value="{!a.Status}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Thanks,

Aaron
Hello,
 
I would like to create a “Clone” button on the Asset related list where the user can select the assets then hit the clone button to clone the assets.  I am assuming I need to create a visualforce page but I am not sure where to begin.  Any help would be much appreciated.
 
Thanks,
 
Aaron 
Hello,

I am working with flows in our test enviorment and the flow works from a button I created.  However, when I select the button to run the flow I get the below message.  I currently have to hit the back button on my browser to go back to the object and then I have to refresh it to show the results.  Is there a way to imilinate this message and refresh the object to show the flow results?  

User-added image

Thanks,

Aaron
Hello,

I am very new to triggers and code and will need some help with a test class.  I have found the below trigger on the web and added it to my sandbox.  I have tested it and it works great.  The trigger updates a "Contract Status" checkbox on the account if there is an active contract associated to it.  Additionally, it will set the checkbox to false if there are no active contracts. 

I am now trying to use a changset to push this into production but I think I need to create a test class to validate it in Prod.  I could be wrong with this assumption.  Can someone please help create a test class or guide me through the process to push this into production?
 
trigger AaronPTest on Contract (after insert, after Update) {
 
    Set<Id> setAccountId = new Set<Id>();  
 
    List<Account> lstToUpdate = new List<Account>();
 
    for(Contract rec : Trigger.New)
 
    {
 
        setAccountId.add(rec.AccountId);
 
    }
 
    List<Account> lstAccount = [SELECT Id,(SELECT Id FROM Contracts WHERE Contract_Status__c = true),Contract_Status__c FROM Account Where Id IN:setAccountId];
 
    for(Account acc : lstAccount)
 
    {
 
        if(acc.Contracts.size() > 0 && !acc.Contract_Status__c){
 
            acc.Contract_Status__c = true;
 
            lstToUpdate.add(acc);
 
        }
 
        else if(acc.Contracts.size() == 0 && acc.Contract_Status__c)
 
        {
 
            acc.Contract_Status__c = false;
 
            lstToUpdate.add(acc);
 
        }
 
    }
 
         Database.update(lstToUpdate);
}
 
 
Thanks,
 
Aaron
 
 
Hello,
 
I am very new to triggers and classes and have recently been assigned a task to populate an Account Status field on the account based on the related contract status.  I have researched this and came across another post with the same question so I have tried to mirror this. 
 
I have created a checkbox labeled Active_Contract__c on both the Account and Contract objects.  I would like the trigger to set the Active_Contract__c to true on the account if there are any related contracts where the Active_Contract__c is also set to true.  If all contracts related to the Account turns to inactive (false) then I would like to set the Active_Contract__c to false on the account.
 
I found the below trigger but I think I will need to create a Class as well.  Again, I am very new to this and any help would be much appreciated.
 
 
trigger OnAccountCreated on Contract(after insert, after Update) {

    Set<Id> setAccountId = new Set<Id>();   

    List<Account> lstToUpdate = new List<Account>();

    for(Contract rec : Trigger.New)

    {

        setAccountId.add(rec.AccountId);

    }

    List<Account> lstAccount = [SELECT Id,(SELECT Id FROM Contracts WHERE Active_Contract__c = true),Active_Contract__c FROM Account Where Id IN:setAccountId];

    for(Account acc : lstAccount)

    {

        if(acc.Contracts.size() > 0 && !acc.Active_Contract__c){

            acc.Active_Contract__c = true;

            lstToUpdate.add(acc);

        }

        else if(acc.Contracts.size() == 0 && acc.Active_Contract__c)

        {

            acc.Active_Contract__c = false;

            lstToUpdate.add(acc);

        }

    }

         Database.update(lstToUpdate);
}
 
Thanks,

Aaron
Hello,

We have the below Visualforce Markup which mass eidts the Asset records when the users select the checkboxes next to the assets.  This works perfectly but I would like to take it a step further to clone and mass edit.  How can I incorporate the clone function into this mass edit function?

<apex:page standardController="Asset" recordSetVar="unused" tabStyle="Asset"
sidebar="false">
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >
Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first. 
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}" var="a" id="table">
<apex:column headerValue="Assert Name">
<apex:inputField value="{!a.name}"/>
</apex:column>
<apex:column headerValue="Account Name">
<apex:inputField value="{!a.AccountID}"/>
</apex:column>
<apex:column headerValue="Product">
<apex:inputField value="{!a.Product2Id}"/>
</apex:column>
<apex:column headerValue="Contract">
<apex:inputField value="{!a.Contract__c}"/>
</apex:column>
<apex:column headerValue="Version">
<apex:inputField value="{!a.Version__c}"/>
</apex:column>
<apex:column headerValue="Asset Start Date">
<apex:inputField value="{!a.Asset_Start_Date__c}"/>
</apex:column>
<apex:column headerValue="Asset End Date">
<apex:inputField value="{!a.Asset_End_Date__c}"/>
</apex:column>
<apex:column headerValue="PPT ID">
<apex:inputField value="{!a.PPT_ID__c}"/>
</apex:column>
<apex:column headerValue="Quantity">
<apex:inputField value="{!a.Quantity}"/>
</apex:column>
<apex:column headerValue="Tenant Name">
<apex:inputField value="{!a.Tentant_Name__c}"/>
</apex:column>
<apex:column headerValue="Status">
<apex:inputField value="{!a.Status}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Thanks,

Aaron
Hello,
 
I would like to create a “Clone” button on the Asset related list where the user can select the assets then hit the clone button to clone the assets.  I am assuming I need to create a visualforce page but I am not sure where to begin.  Any help would be much appreciated.
 
Thanks,
 
Aaron 
Hello,

I am working with flows in our test enviorment and the flow works from a button I created.  However, when I select the button to run the flow I get the below message.  I currently have to hit the back button on my browser to go back to the object and then I have to refresh it to show the results.  Is there a way to imilinate this message and refresh the object to show the flow results?  

User-added image

Thanks,

Aaron