• Imo J
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 4
    Replies
How to write a batch for only one Account to update YtDRevenue field if the related Invoices SUM(Normalized_Amount__c) NormalizeAmount,
FROM Invoice__c   
WHERE Category_Invoice__c != 'Monthly'
AND Status__c != 'invoice_canceled' 
AND Date_Invoice__c= THIS_YEAR
AND Date_Invoice__c <= TODAY
We are having one big Account which is not updating due to 1.5 lack of invoices. I wanted to update automatically with a trigger or a batch, please help me out.
The Account id is 001b000003ryQVMAA2 but I think it would be better with a custom label and not hard coded.
I am new in apex so it would be very helpful if someone would help me out.
Thanks a lot!!!
 
  • September 27, 2019
  • Like
  • 0
I want to make one batch class for the following:
I need to create 2 fields in account: AllRevenue and Ytd.
AllRevenue is the SUM of all the Amounts of all Invoices of the Account WHERE Category_Invoice__c != 'Monthly' AND Status__c != 'invoice_canceled' .
Ytd is the SUM of all the Amounts of all Invoices of the Account WHERE Category_Invoice__c != 'Monthly' AND Status__c != 'invoice_canceled' AND Date_Invoice__c= THIS_YEAR AND Date_Invoice__c <= TODAY.
  • July 25, 2019
  • Like
  • 0
In Account object I have two fields which is taking the values from the Invoice related objects. How to write test class? I am new in development so please help me out to learn to write test classes. 
What are the best practices for test classes on related objects.
Thanks
  • June 28, 2019
  • Like
  • 0
I am having one class which I am getting only 64% code coverage. Please help me out. Here is my class:
public class TriggerCalculateNormalizeInInvoiceGroup implements Triggers.Handler {
    
    public Set<ID> newEntitiesIds = new Set<ID>();
    public Set<ID> oldEntitiesIds = new Set<ID>();
    
    public list<Account> invoicesToUpdate = new list<Account>();
    public list<Account> oldInvoicesToUpdate = new list<Account>();
    
    public list<Account> invToUpdate = new list<Account>();
    public list<Account> oldInvToUpdate = new list<Account>();
    
    public void Handle(){
        storeData();
        processData();
        saveData();
    }   
    
    private void storeData(){
        Map<id,Invoice__c> newInvoices = (Map<ID,Invoice__c>) Trigger.newMap;
        
        for(Invoice__c i: newInvoices.Values()){
            newEntitiesIds.add(i.Account__c);
        }
        
        if(Trigger.isUpdate){
            for(Invoice__c i: (List<Invoice__c>) Trigger.Old){
                if(i.Account__c != newInvoices.get(i.id).Account__c){
                    oldEntitiesIds.add(i.Account__c);
                }
            }
        }
    }
    
    private void processData(){
        for(AggregateResult ar: [SELECT SUM(Normalized_Amount__c) NormalizeAmount, Grouping(Account__c), Account__c
                                 FROM Invoice__c
                                 WHERE Category_Invoice__c != 'Monthly' AND Status__c != 'invoice_canceled' 
                                 AND Account__c IN: newEntitiesIds
                                 GROUP BY Account__c]){
                                     if((ID)ar.get('Account__c') != null){
                                         invoicesToUpdate.add(new Account (
                                             ID = (ID)ar.get('Account__c'),
                                             AllTimeRevenue__c = (Double)ar.get('NormalizeAmount')
                                         ));
                                     }
                                 } 
         for(AggregateResult ar: [SELECT SUM(Normalized_Amount__c) NormalizeAmount, Grouping(Account__c), Account__c
                                 FROM Invoice__c
                                 WHERE Category_Invoice__c != 'Monthly' AND Status__c != 'invoice_canceled' 
                                 AND Date_Invoice__c= THIS_YEAR AND Date_Invoice__c <= TODAY AND Account__c IN: newEntitiesIds
                                 GROUP BY Account__c]){
                                     if((ID)ar.get('Account__c') != null){
                                         invToUpdate.add(new Account (
                                             ID = (ID)ar.get('Account__c'),
                                             YtD_Revenue_for__c = (Double)ar.get('NormalizeAmount')
                                         ));
                                     }
                                 }
        
        if(Trigger.isUpdate){
            for(AggregateResult ar: [SELECT SUM(Normalized_Amount__c) NormalizeAmount, Grouping(Account__c), Account__c
                                     FROM Invoice__c
                                     WHERE Category_Invoice__c != 'Monthly' AND Status__c != 'invoice_canceled' 
                                     AND Account__c IN: oldEntitiesIds
                                     GROUP BY Account__c]){
                                         if((ID)ar.get('Account__c') != null){
                                             oldInvoicesToUpdate.add(new Account (
                                                 ID = (ID)ar.get('Account__c'),
                                                 AllTimeRevenue__c = (Double)ar.get('NormalizeAmount')
                                             ));
                                         }
                                     } 
             for(AggregateResult ar: [SELECT SUM(Normalized_Amount__c) NormalizeAmount, Grouping(Account__c), Account__c
                                     FROM Invoice__c
                                     WHERE Category_Invoice__c != 'Monthly' AND Status__c != 'invoice_canceled' 
                                     AND Date_Invoice__c= THIS_YEAR AND Date_Invoice__c <= TODAY AND Account__c IN: oldEntitiesIds
                                     GROUP BY Account__c]){
                                         if((ID)ar.get('Account__c') != null){
                                             oldInvToUpdate.add(new Account (
                                                 ID = (ID)ar.get('Account__c'),
                                                 YtD_Revenue__c = (Double)ar.get('NormalizeAmount')
                                             ));
                                         }
                                     }
        }
    }
    
    private void saveData(){
        if(!invoicesToUpdate.isEmpty()){
            update invoicesToUpdate;
        }
        if(!invToUpdate.isEmpty()){
            update invToUpdate;
        }
        
        if(Trigger.isUpdate){
            if(!oldInvoicesToUpdate.isEmpty()){
                update oldInvoicesToUpdate;
            }
        }
         if(Trigger.isUpdate){
            if(!oldInvToUpdate.isEmpty()){
                update oldInvToUpdate;
            }
        }
    }
}

 
  • June 28, 2019
  • Like
  • 0
-we are currently sending all the Invoices from the Platform to Salesforce (via the famous web-service)
-by having those invoices in SF, we can create reports
-but could we report on those invoice by simply doing an “api call” or something similar to the Platform instead of storing the data in SF (ie instead of duplicating in SF the data that is in the Platform)?
  • June 28, 2019
  • Like
  • 0
How to run a schedulable class every 1 min?
  • June 10, 2019
  • Like
  • 0
Hi there, 

I need to edit my team's opportunities and edit the "Review Notes" field.

How to do that?

Thanks and regards
Imo
  • December 07, 2018
  • Like
  • 0
How to export results from an SOQL query to CSV?
Currently I'm using workbench.developerforce.com, having 11500 records,view as: bulk csv, and here also its fail : Failed: InvalidBatch : Failed to process query: FUNCTIONALITY_NOT_ENABLED: Foreign Key Relationships not supported in Bulk Query. 
I downloaded FuseIT SFDC Explorer its shows that Failed to create an instance of FuseIT.G4S.SalesforceConnector.Entities.GenericSalesforceEnt‌​ity from htm__Organization_Assignment__c -> result.Id is required for an existing object. Parameter name : result.
How could I export results to CSV?
  • October 21, 2016
  • Like
  • 0
-we are currently sending all the Invoices from the Platform to Salesforce (via the famous web-service)
-by having those invoices in SF, we can create reports
-but could we report on those invoice by simply doing an “api call” or something similar to the Platform instead of storing the data in SF (ie instead of duplicating in SF the data that is in the Platform)?
  • June 28, 2019
  • Like
  • 0
How to run a schedulable class every 1 min?
  • June 10, 2019
  • Like
  • 0
I need additional help with this:

If you want to copy timezone information from contact to related tasks then write a trigger on Task.
trigger updateTimeZone on Task (before insert, before update) { //Contact Ids Set <ID> contactIDs = new Set <ID> (); for (Task t: Trigger.new){ if (t.whoId != NULL){ contactIDs.add(t.whoId); } } //Create a map to match the task related to ID's with their corresponding account ID's Map<ID, Contact> contactMap = new Map<ID, Contact> ([Select ID, TimeZone__c from Contact where ID in :contactIDs]); //Check contactId and update timezone of the task for (Task t: Trigger.new){ if (contactMap.containsKey(t.whoId)){ t.TimeZone__c = contactIDs.get(t.whoId).TimeZone__c; } } }
Replace TimeZone__c field with the respected fields from contact and task.

**I keep getting this error when I copy and past the trigger you sent me. 
Error: Compile Error: No such column 'TimeZone__c' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 10 column 55


What do I need to do?
What do you mean by replace TimeZone__c field with respected fields contact and task?

Sorry I am new to all of this and trying to figure it all out but just hard for me.

If you could please help me or lead me in the right direction I would greatly appreciate it! 

Thank you-
Lindsey W.