• Viktor Bakanov
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
Hello!
I'm new to apex, please advise.
I have created the trigger that create child record based on parent field value. And I need to start this process avaery day at once for all records. So i write the batch process which search for all records where conditions are met, and set the checkbox to true if it does.
And the problem is when the batch process completes the trigger doesn't fire at all. In the Apex Jobs found error: Error Message
Below my trigger and batch processes:
Batch:
global class ITAssetProessingBatch implements Database.Batchable<sobject>{
  global String [] email = new String[] {'VBakanov@bcsprime.com'};
  
  //Start Method
  global Database.Querylocator start (Database.BatchableContext BC) {
    return Database.getQueryLocator('SELECT id, Name, FirstDateOfMonth__c, FrstDayOfMnth__c, Status__c FROM IT_Asset__c WHERE FirstDateOfMonth__c = today AND Status__c = \'Activated\' AND FrstDayOfMnth__c = false');//Query which will be determine the scope of Records fetching the same
  }

  //Execute method
  global void execute (Database.BatchableContext BC, List<sobject> scope) {
    List<IT_Asset__c> ITAList = new List<IT_Asset__c>();
    List<IT_Asset__c> updtaedITAList = new List<IT_Asset__c>();
    for (sObject objScope: scope) { 
        IT_Asset__c newObjScope = (IT_Asset__c)objScope ;
        newObjScope.FrstDayOfMnth__c = true;
        updtaedITAList.add(newObjScope);
        System.debug('Value of UpdatedITAList'+updtaedITAList);
    } 
        if (updtaedITAList != null && updtaedITAList.size()>0) {
            Database.update(updtaedITAList); System.debug('List Size '+updtaedITAList.size());
        }
  }
    
//Finish Method
  global void finish(Database.BatchableContext BC){
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  //Below code will fetch the job Id
  AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors, a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById, a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];//get the job Id
  System.debug('$$$ Jobid is'+BC.getJobId());

  //below code will send an email to User about the status
  mail.setToAddresses(email);
  mail.setReplyTo('VBakanov@bcsprime.com');
  mail.setSenderDisplayName('Apex Batch Processing Module');
  mail.setSubject('Batch Processing '+a.Status);
  mail.setPlainTextBody('The Batch Apex job processed  '+a.TotalJobItems+'batches with  '+a.NumberOfErrors+'failures'+'Job Item processed are'+a.JobItemsProcessed);
  Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
  }
    //Scheduler Method to scedule the class
  global void execute(SchedulableContext sc)
    {
        ITAssetProessingBatch conInstance = new ITAssetProessingBatch();
        database.executebatch(conInstance,100);
    }
}
Trigger:
Trigger CashFlow on IT_Asset__c (after update)
{
         List<Cash_Flow__c> sub=new List<Cash_Flow__c>();
     for(IT_Asset__c it : Trigger.new)
     {
           if(it.FrstDayOfMnth__c == true)
           {
                   Cash_Flow__c cf=new Cash_Flow__c();
                   cf.CurrencyIsoCode=it.CurrencyIsoCode;
                   cf.Date__c=it.Start_Date__c;
               	   cf.RecordTypeId='012b0000000UOay';
                   cf.IT_Asset__c=it.Id;
                   //add other fields of subject here and add volunteer values in that.
                 
                   sub.add(cf);
            }
            if(sub.size()>0)
            insert sub;
     }
}

I deactivate the trigger and run batch and it completes without errors, so i think the problem in trigger.... Maybe I made something wrong?
 
Hello!
I have a related list on my vf page called Account Number. This page uses standard controller - Account. So on this page i show Account Numbers related list for Account.
To show necessary record, i add the render component. My code below:
<apex:page standardController="Account" showHeader="true">
    
    <apex:pageBlock title="{!account.name}">
      <apex:pageBlockSection title="Account Numbers" columns="1">      
        <apex:pageBlockTable title="Account Numbers" var="acnum" value="{!account.Account_Numbers__r}" border="1" cellpadding="4" cellspacing="1" width="100%">
            <apex:column >
                <apex:facet name="header">Action</apex:facet>
                <apex:OutputLink value="{!$Action.Account_Number__c.Edit}" rendered="{!acnum.Status__c ='Created'}">Edit</apex:outputLink>
                <apex:OutputText value=" | " rendered="{!acnum.Status__c ='Created'}"> </apex:OutputText>
                <apex:OutputLink value="{!$Action.Account_Number__c.Delete}" rendered="{!acnum.Status__c ='Created'}">Del</apex:outputLink>
            </apex:column>        
            <apex:column >
                <apex:facet name="header">Name</apex:facet>
                <apex:OutputLink value="https://cs87.salesforce.com/{!acnum.id}" rendered="{!acnum.Status__c ='Created'}">{!acnum.Name}</apex:OutputLink>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Account #</apex:facet>
                <apex:OutputText value="{!acnum.Account_No__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Status</apex:facet>
                <apex:OutputText value="{!acnum.Status__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>            
            <apex:column >
                <apex:facet name="header">Trading Account</apex:facet>
                <apex:OutputText value="{!acnum.Account_Number_Old__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Account #</apex:facet>
                <apex:OutputText value="{!acnum.Account_No__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Markets</apex:facet>
                <apex:OutputText value="{!acnum.Markets__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">TCA Settlement Account</apex:facet>
                <apex:OutputText value="{!acnum.TCA_Settlement_Account__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>                
            <apex:column >
                <apex:facet name="header">Trading Account Type</apex:facet>
                <apex:OutputText value="{!acnum.Trading_Account_Type__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column> 
            <apex:column >
                <apex:facet name="header">Account Setup With</apex:facet>
                <apex:OutputText value="{!acnum.Account_Setup_With__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column> 
            <apex:column >
                <apex:facet name="header">Record Type</apex:facet>
                <apex:OutputText value="{!acnum.RecordType.Name}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Login</apex:facet>
                <apex:OutputText value="{!acnum.Login__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>                                                                                             
        </apex:pageBlockTable>
      </apex:pageBlockSection>

This is work for me pretty good, but the table shows now empty rows. See the picture:
Empty rows
It seems there two records, that doesn't meet the criteria of rendered component.
So how can i hide this empty rows from the related list?
Hello!
I'm new to apex, please advise.
I have created the trigger that create child record based on parent field value. And I need to start this process avaery day at once for all records. So i write the batch process which search for all records where conditions are met, and set the checkbox to true if it does.
And the problem is when the batch process completes the trigger doesn't fire at all. In the Apex Jobs found error: Error Message
Below my trigger and batch processes:
Batch:
global class ITAssetProessingBatch implements Database.Batchable<sobject>{
  global String [] email = new String[] {'VBakanov@bcsprime.com'};
  
  //Start Method
  global Database.Querylocator start (Database.BatchableContext BC) {
    return Database.getQueryLocator('SELECT id, Name, FirstDateOfMonth__c, FrstDayOfMnth__c, Status__c FROM IT_Asset__c WHERE FirstDateOfMonth__c = today AND Status__c = \'Activated\' AND FrstDayOfMnth__c = false');//Query which will be determine the scope of Records fetching the same
  }

  //Execute method
  global void execute (Database.BatchableContext BC, List<sobject> scope) {
    List<IT_Asset__c> ITAList = new List<IT_Asset__c>();
    List<IT_Asset__c> updtaedITAList = new List<IT_Asset__c>();
    for (sObject objScope: scope) { 
        IT_Asset__c newObjScope = (IT_Asset__c)objScope ;
        newObjScope.FrstDayOfMnth__c = true;
        updtaedITAList.add(newObjScope);
        System.debug('Value of UpdatedITAList'+updtaedITAList);
    } 
        if (updtaedITAList != null && updtaedITAList.size()>0) {
            Database.update(updtaedITAList); System.debug('List Size '+updtaedITAList.size());
        }
  }
    
//Finish Method
  global void finish(Database.BatchableContext BC){
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  //Below code will fetch the job Id
  AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors, a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById, a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];//get the job Id
  System.debug('$$$ Jobid is'+BC.getJobId());

  //below code will send an email to User about the status
  mail.setToAddresses(email);
  mail.setReplyTo('VBakanov@bcsprime.com');
  mail.setSenderDisplayName('Apex Batch Processing Module');
  mail.setSubject('Batch Processing '+a.Status);
  mail.setPlainTextBody('The Batch Apex job processed  '+a.TotalJobItems+'batches with  '+a.NumberOfErrors+'failures'+'Job Item processed are'+a.JobItemsProcessed);
  Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
  }
    //Scheduler Method to scedule the class
  global void execute(SchedulableContext sc)
    {
        ITAssetProessingBatch conInstance = new ITAssetProessingBatch();
        database.executebatch(conInstance,100);
    }
}
Trigger:
Trigger CashFlow on IT_Asset__c (after update)
{
         List<Cash_Flow__c> sub=new List<Cash_Flow__c>();
     for(IT_Asset__c it : Trigger.new)
     {
           if(it.FrstDayOfMnth__c == true)
           {
                   Cash_Flow__c cf=new Cash_Flow__c();
                   cf.CurrencyIsoCode=it.CurrencyIsoCode;
                   cf.Date__c=it.Start_Date__c;
               	   cf.RecordTypeId='012b0000000UOay';
                   cf.IT_Asset__c=it.Id;
                   //add other fields of subject here and add volunteer values in that.
                 
                   sub.add(cf);
            }
            if(sub.size()>0)
            insert sub;
     }
}

I deactivate the trigger and run batch and it completes without errors, so i think the problem in trigger.... Maybe I made something wrong?
 
Hello!
I have a related list on my vf page called Account Number. This page uses standard controller - Account. So on this page i show Account Numbers related list for Account.
To show necessary record, i add the render component. My code below:
<apex:page standardController="Account" showHeader="true">
    
    <apex:pageBlock title="{!account.name}">
      <apex:pageBlockSection title="Account Numbers" columns="1">      
        <apex:pageBlockTable title="Account Numbers" var="acnum" value="{!account.Account_Numbers__r}" border="1" cellpadding="4" cellspacing="1" width="100%">
            <apex:column >
                <apex:facet name="header">Action</apex:facet>
                <apex:OutputLink value="{!$Action.Account_Number__c.Edit}" rendered="{!acnum.Status__c ='Created'}">Edit</apex:outputLink>
                <apex:OutputText value=" | " rendered="{!acnum.Status__c ='Created'}"> </apex:OutputText>
                <apex:OutputLink value="{!$Action.Account_Number__c.Delete}" rendered="{!acnum.Status__c ='Created'}">Del</apex:outputLink>
            </apex:column>        
            <apex:column >
                <apex:facet name="header">Name</apex:facet>
                <apex:OutputLink value="https://cs87.salesforce.com/{!acnum.id}" rendered="{!acnum.Status__c ='Created'}">{!acnum.Name}</apex:OutputLink>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Account #</apex:facet>
                <apex:OutputText value="{!acnum.Account_No__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Status</apex:facet>
                <apex:OutputText value="{!acnum.Status__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>            
            <apex:column >
                <apex:facet name="header">Trading Account</apex:facet>
                <apex:OutputText value="{!acnum.Account_Number_Old__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Account #</apex:facet>
                <apex:OutputText value="{!acnum.Account_No__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Markets</apex:facet>
                <apex:OutputText value="{!acnum.Markets__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">TCA Settlement Account</apex:facet>
                <apex:OutputText value="{!acnum.TCA_Settlement_Account__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>                
            <apex:column >
                <apex:facet name="header">Trading Account Type</apex:facet>
                <apex:OutputText value="{!acnum.Trading_Account_Type__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column> 
            <apex:column >
                <apex:facet name="header">Account Setup With</apex:facet>
                <apex:OutputText value="{!acnum.Account_Setup_With__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column> 
            <apex:column >
                <apex:facet name="header">Record Type</apex:facet>
                <apex:OutputText value="{!acnum.RecordType.Name}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Login</apex:facet>
                <apex:OutputText value="{!acnum.Login__c}" rendered="{!acnum.Status__c ='Created'}"/>
            </apex:column>                                                                                             
        </apex:pageBlockTable>
      </apex:pageBlockSection>

This is work for me pretty good, but the table shows now empty rows. See the picture:
Empty rows
It seems there two records, that doesn't meet the criteria of rendered component.
So how can i hide this empty rows from the related list?
Hi all, I want to preface this by saying I have absolutley zero knowledge of coding and how to write an apex trigger. However, I do know the result i'm trying to achieve so I'm hoping my description will be enough for someone to provide some help.

My situation is the following: I have 2 custom objects Volunteer and Subject. What I want to happen is that when a certain field (Volunteer_Status__c), a picklist value, is updated to the selection "Screening Completed" a new record is created under the Subject object that replicates the information stored under the volunteer record.

If someone could provide some instruction it would be much appreciated!

I'm (still) totally green to Apex, so please be patient ;)

 

I have a trigger that updates the record that triggers it and creates a new record in the same object. It works nicely when using 'after update'. But what I actually need that trigger to do is run when a formula changes the value from false to true.

 

That formula is quite complex and using cross-object references and roll-ups to calculate the values, so there is not necessarily an action on the record happening to change the value.

 

My thought was to set it to 'after insert', hoping that the trigger will run every now and then to check whether the conditions are ok to run. But maybe I don't understand properly how this works.

 

Thanks