• Andreea T
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 5
    Replies
Hi there
In the Contact object we are having one checkbox Activity_history_missing__c field so this we want to make it true when there is no linked Activity History to the Contact after 24 hours of the Contact Created date.
How can I achieve this?
Can you please send me sample trigger on Activities so I can update the Contact.
Thanks
 
Hi there,
Please help me to cover only 3 %, my test class covering 72% only, Attaching the screenshot with the red part which needs to cover.
Please guys help me.
Thanks
User-added imageUser-added imageUser-added image
Hi there,
I need to remove one lookup field from the Account (lookup to User) called CSM__c, but it's referencing an apex class, please suggest how can I remove this field.
Here is my apex class
public class CommissionBuilder {
    
    static final set<String> invalidOwnerIds = new Set<String> {'005b0000001Noq0','005b0000000M5sd','005b0000003AC0f'};
    static final Integer StartReferenceYear = 2017;
    static final Integer StartYearTeamLeadersBonus = 2018;
    Map<String,User> MapUsersbyName;
    Map<id,User> MapUsers;
    Map<id,Contract>  mapContracts;
    
	Invoice__c Invoice = new Invoice__c ();
    Commission_Model__c CommissionModel;
    List<Contributer__c> Contributers = new List <Contributer__c> ();
    
    public CommissionBuilder setMapContracts(Map<id,Contract> mapContracts){
        this.mapContracts = mapContracts;
        return this;
    }
     
    public CommissionBuilder setMapUsersID(Map<id,User> MapUsersID){
        this.MapUsers = MapUsersId;
        return this;
    }
    
    public CommissionBuilder setMapUserbyName(Map<String,User> MapUsersbyName){
        this.MapUsersbyName = MapUsersbyName;
        return this;
    }
    
    public CommissionBuilder setInvoice(Invoice__c Invoice){
        this.Invoice = Invoice;
        return this;
    }   
    
    public CommissionBuilder setContributer(List<Contributer__c> Contributers){
        this.Contributers = Contributers;
        return this;
    }
    
    public CommissionBuilder setCommissionModel(Commission_Model__c CommissionModel){
        this.CommissionModel = CommissionModel;
        return this;
    }
    
    public Commission__c Rebuild(Commission__c C){
        C.Commission_Model__c = CommissionModel.id;
        C.BO__c = Invoice.Normalized_Amount__c * (CommissionModel.BO__c/100);
        C.MO__c = Invoice.Normalized_Amount__c * CommissionModel.MO__c/100;
        C.Marketing__c  = CalCommissionModelarketingCommission();
        C.FX_Strategy__c = CalcFXStrategyCommission();
        C.CSM__c = CalcCSMCommission();
        C.Team_Leader__c = CalcTeamLeaderCommission();
        if(!C.Don_t_Recalculate__c) CalcSalesCommission(C);
        return C;
    }
    
    public Commission__c build(){
        Commission__c C = new Commission__c(Commission_Model__c = CommissionModel.id,
        BO__c = Invoice.Normalized_Amount__c * (CommissionModel.BO__c/100),
        Invoice__c = Invoice.id,
        MO__c = Invoice.Normalized_Amount__c * CommissionModel.MO__c/100,
        Marketing__c  = CalCommissionModelarketingCommission(),
        Team_Leader__c = CalcTeamLeaderCommission(),
        FX_Strategy__c = CalcFXStrategyCommission(),
        CSM__c = CalcCSMCommission());
        CalcSalesCommission(C);
        return C;
    }
    
       ...
}
Please help me how can I remove this field.
Thanks
 
Hello friends, 
Please help me to write a test class for this class
public class TriggerTaskUpdateLastNextTask implements Triggers.Handler  {
	public void handle(){
        Map <id,List <Task>> mapAcc = new Map <id,List <Task>> (); 
        Map <id,List <Task>> mapLead = new Map <id,List <Task>> ();  
        List <Account> AtoUpdate = new List <Account>();
        List <Account> TasktoAccUpdate = new List <Account>();
        List <Lead> LtoUpdate = new List <Lead> ();
        Map<id,Account> accounts = new Map<id,Account>();
        Map <id,Task> mapTasks = new Map <id,Task> ();
        for(Task T: (List <Task>) Trigger.new) {
            if(T.whoid != NULL && ((string)T.whoid).startswith('00Q')) mapLead.put(T.whoid,new List <Task> {T});
            if(T.whatid!= NULL && ((string)T.whatid).startswith('001')) mapAcc.put(T.whatid,new List <Task> {T});
            if(T.whatid!= NULL && ((string)T.whatid).startswith('006')) mapAcc.put(T.whatid,new List <Task> {T});
        }
        Map <id,Account> mapAccounts = new Map <id,Account> ();
        Map <id,Account> mapAccTaskCompleted = new Map <id,Account> ();
        Map <id,Lead> mapLeads = new Map <id,Lead> ();
        for(Account A :[SELECT id,True_last_activity__c,Next_Activity_Date__c FROM Account WHERE id in: mapAcc.keySet()]) {
            mapAccounts.put(A.id,A);
        }
        for(Account Acc :[SELECT id,True_last_activity__c,(select id,activitydate from tasks where status = 'Completed' and activitydate != null order by activitydate desc limit 1) FROM Account WHERE id in: mapAcc.keySet()]) {
            mapAccTaskCompleted.put(Acc.id,Acc);
        }

        for(account acct:mapAccTaskCompleted.values()){
           	List <Task> auxT = mapAcc.get(Acct.id);
            if(auxT == NULL) auxT = new List <Task> ();
            for(Task Ts: auxT) {
          if(Ts.ActivityDate !=null && Ts.Status=='Completed') acct.True_last_activity__c = acct.tasks[0].activitydate;
            }
            TasktoAccUpdate.add(Acct);
            
        }
        
        for(Lead L : [SELECT id,True_last_activity__c,Next_Activity_Date__c,Last_Sales_interaction__C FROM Lead WHERE id in: maplead.keySet()]) {
            mapLeads.put(L.id,L);
        }
        for(Account A: MapAccounts.values()) {
           	List <Task> auxT = mapAcc.get(A.id);
            if(auxT == NULL) auxT = new List <Task> ();
            for(Task T: auxT) {
                if(T.ActivityDate > System.Now() && (A.Next_Activity_date__C == NULL || T.activityDate < A.Next_Activity_date__c)) A.Next_Activity_date__c = T.ActivityDate;
        
            }
            Atoupdate.add(A);
        }
        for(Lead L: MapLeads.values()) {
           	List <Task> auxT = mapLead.get(L.id);
            if(auxT == NULL) auxT = new List <Task> ();
            for(Task T: auxT) {
                if(T.ActivityDate > System.Now() && (L.Next_Activity_date__C == NULL || T.activityDate < L.Next_Activity_date__c)) {
                    L.Next_Activity_date__c = T.ActivityDate;                  
                } 
                else if(T.ActivityDate < System.now() && (L.True_last_activity__c == NULL|| T.activityDate > L.True_Last_Activity__c)) {
                    L.True_Last_Activity__c = T.ActivityDate;
                    L.Last_Sales_interaction__C = T.Type;      
                    } 
            }
            Ltoupdate.add(L);
        }
        update Atoupdate;
        update TasktoAccUpdate; 
        update Ltoupdate;
	}    
}

 
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!!!
 
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.
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
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;
            }
        }
    }
}

 
-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)?
How to run a schedulable class every 1 min?
Hi there, 

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

How to do that?

Thanks and regards
Imo
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?
Hi there,
Please help me to cover only 3 %, my test class covering 72% only, Attaching the screenshot with the red part which needs to cover.
Please guys help me.
Thanks
User-added imageUser-added imageUser-added image
-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)?
How to run a schedulable class every 1 min?
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.