0

I'm trying to use batch apex on Lastlogindate. I have to capture the system generated lastlogindate into a custom field .Here is the code

global class CaptureLastLoginDate implements Database.Batchable<sObject>{

//This is the query that is passed to the execute method.  .

String query = 'SELECT id, LastLoginDate FROM User WHERE Id=:UserInfo.getUserId()';

global database.queryLocator start(Database.BatchableContext BC) {
    return database.getQueryLocator(query);

} 
//close start method
global void  execute(Database.BatchableContext BC, List<User> scope) {
User u = [SELECT id, LastLoginDate FROM User WHERE Id=:UserInfo.getUserId()];


   // Iterate through the whole query 
    for(User a : scope) {

            a.LastLoginDate__c = u.LastLoginDate;
        } //close if statement
     update LastLoginDate__c;
     }

    //close for-loop

 //close execute method

  global void finish(Database.BatchableContext BC) {


  } //close finish method
} //close class

and the error i'm getting is**

:E*rror: Compile Error: Argument type of global method must also be global: LIST at line 12 column 15*

Thank you in advance

**

| improve this question | | | | |
  • Looks like this is a duplicate of your question at boards.developerforce.com/t5/Apex-Code-Development/Batch-apex/…. Why are you asking the same in two different places at once? – FrankZ Dec 11 '13 at 12:54
  • 2
    @FrankZ: I don't see anything wrong with asking the same question in two places, not all users are active members of both sites. – PepeFloyd Dec 11 '13 at 13:28
  • @PepeFloyd it's the "at once" I was more concerned about. As long as Sindoora keeps all forums updated about discussions going on in the other places it's fine by me. – FrankZ Dec 11 '13 at 13:34
  • @Frankz Hi,Frankz all the salesforce users are not activate members in stack. That's y i posted in two different place. – Sindoora Dec 12 '13 at 6:35
1

Not sure why you get that error message. I can save the class using API v29 after making some other changes (more on that later). Which API version is this class using?

To save the class I had to change update LastLoginDate__c; to update scope;. Then the system complained about LastLoginDate__c not existing within User. Removing the __c caused the system to tell me that this field is not modifiable - and rightly so.

Maybe you should go back to the drawing board with your idea. Not sure what you try to achieve using this class.

Oh, and one more thing: I think UserInfo.getUserId() will return null in a Batch APEX context.

| improve this answer | | | | |
  • 1
    Thanks.Error has been resolved.The reson y i got error is:already there exists and apex class on user so that it fired error message. – Sindoora Dec 12 '13 at 6:38
  • @Frankz.In this code we are trying to capture system generated LastLoginDate into a custom Field(LastLogionDate__c) on user. Generally on User few field are not exposed like createdby,LastLogin,... to get those fields info we use UserInfo.getUserId() – Sindoora Dec 12 '13 at 6:40
  • 2
    Sindoora, it would be great if you would write up the answer, post it, and mark your question as answered for other people who might struggle with this problem. Much thanks! – pchittum Jan 10 '14 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.