• Sumit Sharma 186
  • NEWBIE
  • 5 Points
  • Member since 2017
  • Sr. Salesforce Developer
  • Mirketa Inc


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi,

We have a need to schedule a batch that will perform some action if the user has not logged in in the last 24hours. On the User object, there is a LastLoginDate field which is a DateTime field. 

I want to write a SOQL query that will filter out (not select) users who have logged in with last 24hours. I am having difficulty understanding the correct syntex and need help determining what would be the best approach. What would be the recommended way to do this?
 
/*
 *i tried this but it was giving very weird response.
  *if today = 3/30/2017, when i do the following below i see that in the debug statements that it pulling users with a lastlogindate of 2017-03-30T07:XX:XX values
 * if i print DateTime.Now() i am getting a result of 2017-03-31T01:05:53 (if i were to run it on 3/30/2017 6:05pm PT
  */
List<User> usrs = [Select Id, LastLoginDate, IsActive, Name 
                                  From User
                                  Where LastLoginDate = TODAY];

The goal is to get the set of records where all user.lastlogindate >= 3/29/2017T18:05:53 and user.LastLoginDate <=3/30/2017T18:05:53 (basically within the last 24hours when the logic is ran). Any thoughts?
  • March 31, 2017
  • Like
  • 0
How to add update event on this code and how i write test class for this, i am new can any one help me..
trigger UpdateCustomerPO on AcctSeedERP__Sales_Order_Line__c (after insert,after update) {

Map<ID, AcctSeedERP__Sales_Order__c> parentSalesOrder = new Map<ID, AcctSeedERP__Sales_Order__c>(); 
  
  List<Id> listIds = new List<Id>();

  for (AcctSeedERP__Sales_Order_Line__c childObj : Trigger.new) {
    listIds.add(childObj.AcctSeedERP__Sales_Order__c);
  }


  parentSalesOrder = new Map<Id, AcctSeedERP__Sales_Order__c>([SELECT id,(SELECT ID, Customer_PO__c FROM AcctSeedERP__Sales_Order_Line__r) FROM AcctSeedERP__Sales_Order__c WHERE ID IN :listIds]);

  for (AcctSeedERP__Sales_Order_Line__c sales: Trigger.new){
     AcctSeedERP__Sales_Order__c myParentOpp = parentSalesOrder.get(sales.AcctSeedERP__Sales_Order__c);
     myParentOpp.Customer_PO__c = sales.Customer_PO__c;
  }

  update parentSalesOrder.values();
}
Thank You
I am getting below exception
Execution of BeforeInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old: Class
I create a class which insert task for account object while creating task for a Lead object, below i hardcoded the account whatId. I created trigger for Task and call CreateTaskInAccount.createTask() from trigger, but its not happening like so.
Please share your feedback.

public class CreateTaskInAccount
{
 public void createTask(List<Task> TaskFromTrigger)
  {
  
    Account targetWhatId= [SELECT a.Id FROM Account a where a.Name='NishantAccount'];
    
    List<Task> tskList= new List<Task>();
    
    for(Task varTask: TaskFromTrigger)
    {
      Task tsk= new Task();
      
      tsk=varTask;
      tsk.WhatId=targetWhatId.Id;
            
                  
      tskList.Add(tsk);
    }
  
    Database.Insert(tskList);
  }
}
------------------------------------
trigger CreateTaskInAccount on Task (before insert, before update) {

  List<Task> lTask = new List<Task>();
  
    
  CreateTaskInAccount objAccount=new CreateTaskInAccount();
  objAccount.createTask(Trigger.new);
}

Tanks in advance