• Luffy Carl_op
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 5
    Replies
I need a Date/time type record of this user's login time, which will correct to hours, miuntes, seconds. 
BTW, is there a document which i could find all the standard field of User's API name by?
Now, I seted up a system, for users login and logout every. I want to add one function that System checks records everyday, if anyone didn't logged, send a email to him.I have use the schedule apex class find exceptional users,got their ID, BUT i don't know how to write the email body. I want to show some user's info in this email, just like Hello, Luffy. But it's invalid. Please help me.Thanks.
//Here i get the list of exception users. 
List<User> lu = new List<User>();
        lu = [select Id, Name, Email
             (SELECT Name, BeginTime__c, EndTime__c From WorkTime__r
             )  From User
        ];
        //Judge if the list is null,if user don't login , add to list
        List<Id> em = new List<String>();
        for(User u : lu){
            if( [select Name, BeginTime__c, EndTime__c, WorkerRef__c From WorkTime__c
                    Where WorkerRef__c =:u.id
                    And DAY_ONLY(BeginTime__c) =: Date.Today()
                    ].isEmpty() ){
                em.add(u.Id);
           }
        }
//In this template, it's both invalid that using WorkTime__c's fields or User's fields
        String dn =  'System_Exception_Records';
        Id tid;
        tid = [select id from EmailTemplate where developername =:dn ].id;   
           
        for(Id saddr : em){
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setTargetObjectId(saddr);
            email.setTemplateId(tid);
            email.setSaveAsActivity(false);
            Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
        }

 
There are two buttons in my Visualforce Page.Show All reports, and Show This Month reports.And a function,which will update single record in page. I want to refresh the list after updating one record.But I don't know which one button was clicked, or to say, which list is in this page.How can I judge it? thanks.
public with sharing class ManagePageCtrl{
    public List<SelectOption> optionMonth {get; set;}
    public String selectedmonth {get; set;}
    
    public List<WorkTime__C> relist {get; set;}

    public ManagePageCtrl(){
        relist = new List<WOrkTime__C>();
        
        optionMonth = new List<SelectOption>();
                optionMonth.add(new SelectOption('0' , '-none-'));
                optionMonth.add(new SelectOption('12', 'December'));
                optionMonth.add(new SelectOption('11', 'November'));
                optionMonth.add(new SelectOption('10', 'October'));
                optionMonth.add(new SelectOption('9' , 'September'));
                optionMonth.add(new SelectOption('8' , 'August'));
                optionMonth.add(new SelectOption('7' , 'July'));
                optionMonth.add(new SelectOption('6' , 'June'));
                optionMonth.add(new SelectOption('5' , 'May'));
                optionMonth.add(new SelectOption('4' , 'April'));
                optionMonth.add(new SelectOption('3' , 'March'));
                optionMonth.add(new SelectOption('2' , 'February'));
                optionMonth.add(new SelectOption('1' , 'January'));
        
    }
    
    public pageReference showWorks(){
        
        
        if(selectedmonth == '0'){
            relist = [select Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c 
                where WorkerRef__r.Name = :selectedsubordinate
                And CALENDAR_MONTH(BeginTime__c) = :Date.Today().Month()
                Order by BeginTime__c DESC
                ];
        }else{
            relist = [select Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c 
                where WorkerRef__r.Name = :selectedsubordinate
                And CALENDAR_MONTH(BeginTime__c) = :
                
                ];
        }
        if (relist.isEmpty()) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This Employee has not ATTENDANCE INFORMATION this month.'));
            return null;
        }   
        return null;     
    }
    
    public pageReference showAllWorks(){
        
        relist = [select  Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c 
            where WorkerRef__r.Name = :selectedsubordinate
            Order by BeginTime__c DESC
            ];
        
        if (relist.isEmpty()) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This Employee has not ATTENDANCE INFORMATION.'));
            return null;
        }   
        return null;     
    }
    
    public pageReference saveSingleRecord(){
        string recId = ApexPages.currentpage().getParameters().get('myRecId');
        
        WorkTime__c mySingleRec;
        for (WorkTime__c c : relist) {
            if (recId == c.Name) {
                mySingleRec = c;
                break;
            }
        }
        if (mySingleRec != null)
            update mySingleRec;
//It's it, How can i judge which one button was clicked and return showAllWorks() or showWorks()?
        return showAllWorks();
        
    }
}


 ===========================================
 
<apex:page controller="ManagePageCtrl" tabStyle="WorkTime__c" sidebar="false">
    
    <apex:pageBlock title="Hello, {!$User.LastName}! W id="thePageBlock">
        <apex:pageMessages />
        
        <apex:commandButton value="Show All Reports" action="{!showAllWorks}"/>
        Month:<apex:selectList multiselect="false" value="{!selectedmonth}" size="1" style="width:230px">
                <apex:selectOptions value="{!optionMonth}"></apex:selectOptions>
              </apex:selectList>  
        <apex:commandButton value="Show This Month Reports" action="{!showWorks}" />
              
        <apex:actionStatus id="loadingStatus" startText="Please Wait. Processing..." />
        
        <apex:pageBlockTable value="{!relist}" var="rec" id="myTable">
            <apex:column headerValue="ID" value="{!rec.Name}" /> 
            <apex:column headerValue="LoginTime" value="{!rec.BeginTime__c}" />
            <apex:column headerValue="LogoutTime" value="{!rec.EndTime__c}" />
            <apex:column headerValue="Notes"> 
                <apex:inputText value="{!rec.Notes__c}" />
            </apex:column>
            <apex:column headerValue="Update">
                <apex:commandLink action="{!saveSingleRecord}" rerender="thePageBlock" status="loadingStatus">
                    Update
                    <apex:param value="{!rec.Name}" name="myRecId" />  
                </apex:commandLink>
            </apex:column>
        </apex:pageblocktable>        
    </apex:pageBlock>
</apex:form>
</apex:page>

 
There are a list in my page, whose records is coming from object, quering by apex class. 
How can I batch remove records from this list?
 
//EmailAddress is known, the  List of  address i want to send email.

String dn =  'My_Template_Name';
        
        Id tid;
        tid = [select id from EmailTemplate where developername =:dn ][0].id;   
           
        for(String saddr : EmailAddress ){
           
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            string [] toaddress= New string[]{saddr};
            email.setTemplateId(tid);
            email.setSubject('Attendance_System_Exception_Records_Alert');
            email.setPlainTextBody('Testing Apex Scheduler-Body');
            email.setToAddresses(toaddress);
            Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
        }
Is there some problem with my code?
the schedule job give me a ERROR:

System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing targetObjectId with template: []

If you can help me , please.
 
Hello Everyone. I'm doing a simple attendance system. There is a function that system will check every users' logging infomation everyday, and send e-mail to the absenteeism. I'm a beginner of sfdc and that will be not enough time to learn about batch job or schedule apex, which because of my leader want see the result in the near future. so if there is some a little bit simple methods to do this , please help me.
 
There is a page to add new record of the worktime__c object,which having a loop-up field to user,named Worker__c. I create a selectList to show worktime__c.Worker__r.Name, and others info. But i save this record by the method in apex class. It will just save others info, not the Worker__c. How can I save those info at one time?
There is a object, with a date/time field. I want add a record from visualforce page, What kind of component should i use?
Hello, at now, I want send e-mails to the users in my system, who have a exceptional report. I have written the Text Email Template, but I can't write the script of Workflow Rule.Is there anyone could help me with this rule? This may means: in oneday, the user did't login(the login__c will be null of this day before 24:00), system will send e-mail to him/her in 24:00.
there is a table in my visualforce page, i want to find out my report with two ways, for exmple, there are show all reports and show reports in this month. they both point to one list in controller. so, how can i judge which one clicked?
For example, if i add a custom field "myposition", how can i get it in apex class?
UserInfo.getMyposition()  or  UserInfo.myposition  are both invalid.
There are two buttons in my Visualforce Page.Show All reports, and Show This Month reports.And a function,which will update single record in page. I want to refresh the list after updating one record.But I don't know which one button was clicked, or to say, which list is in this page.How can I judge it? thanks.
public with sharing class ManagePageCtrl{
    public List<SelectOption> optionMonth {get; set;}
    public String selectedmonth {get; set;}
    
    public List<WorkTime__C> relist {get; set;}

    public ManagePageCtrl(){
        relist = new List<WOrkTime__C>();
        
        optionMonth = new List<SelectOption>();
                optionMonth.add(new SelectOption('0' , '-none-'));
                optionMonth.add(new SelectOption('12', 'December'));
                optionMonth.add(new SelectOption('11', 'November'));
                optionMonth.add(new SelectOption('10', 'October'));
                optionMonth.add(new SelectOption('9' , 'September'));
                optionMonth.add(new SelectOption('8' , 'August'));
                optionMonth.add(new SelectOption('7' , 'July'));
                optionMonth.add(new SelectOption('6' , 'June'));
                optionMonth.add(new SelectOption('5' , 'May'));
                optionMonth.add(new SelectOption('4' , 'April'));
                optionMonth.add(new SelectOption('3' , 'March'));
                optionMonth.add(new SelectOption('2' , 'February'));
                optionMonth.add(new SelectOption('1' , 'January'));
        
    }
    
    public pageReference showWorks(){
        
        
        if(selectedmonth == '0'){
            relist = [select Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c 
                where WorkerRef__r.Name = :selectedsubordinate
                And CALENDAR_MONTH(BeginTime__c) = :Date.Today().Month()
                Order by BeginTime__c DESC
                ];
        }else{
            relist = [select Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c 
                where WorkerRef__r.Name = :selectedsubordinate
                And CALENDAR_MONTH(BeginTime__c) = :
                
                ];
        }
        if (relist.isEmpty()) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This Employee has not ATTENDANCE INFORMATION this month.'));
            return null;
        }   
        return null;     
    }
    
    public pageReference showAllWorks(){
        
        relist = [select  Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c 
            where WorkerRef__r.Name = :selectedsubordinate
            Order by BeginTime__c DESC
            ];
        
        if (relist.isEmpty()) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This Employee has not ATTENDANCE INFORMATION.'));
            return null;
        }   
        return null;     
    }
    
    public pageReference saveSingleRecord(){
        string recId = ApexPages.currentpage().getParameters().get('myRecId');
        
        WorkTime__c mySingleRec;
        for (WorkTime__c c : relist) {
            if (recId == c.Name) {
                mySingleRec = c;
                break;
            }
        }
        if (mySingleRec != null)
            update mySingleRec;
//It's it, How can i judge which one button was clicked and return showAllWorks() or showWorks()?
        return showAllWorks();
        
    }
}


 ===========================================
 
<apex:page controller="ManagePageCtrl" tabStyle="WorkTime__c" sidebar="false">
    
    <apex:pageBlock title="Hello, {!$User.LastName}! W id="thePageBlock">
        <apex:pageMessages />
        
        <apex:commandButton value="Show All Reports" action="{!showAllWorks}"/>
        Month:<apex:selectList multiselect="false" value="{!selectedmonth}" size="1" style="width:230px">
                <apex:selectOptions value="{!optionMonth}"></apex:selectOptions>
              </apex:selectList>  
        <apex:commandButton value="Show This Month Reports" action="{!showWorks}" />
              
        <apex:actionStatus id="loadingStatus" startText="Please Wait. Processing..." />
        
        <apex:pageBlockTable value="{!relist}" var="rec" id="myTable">
            <apex:column headerValue="ID" value="{!rec.Name}" /> 
            <apex:column headerValue="LoginTime" value="{!rec.BeginTime__c}" />
            <apex:column headerValue="LogoutTime" value="{!rec.EndTime__c}" />
            <apex:column headerValue="Notes"> 
                <apex:inputText value="{!rec.Notes__c}" />
            </apex:column>
            <apex:column headerValue="Update">
                <apex:commandLink action="{!saveSingleRecord}" rerender="thePageBlock" status="loadingStatus">
                    Update
                    <apex:param value="{!rec.Name}" name="myRecId" />  
                </apex:commandLink>
            </apex:column>
        </apex:pageblocktable>        
    </apex:pageBlock>
</apex:form>
</apex:page>

 
There are a list in my page, whose records is coming from object, quering by apex class. 
How can I batch remove records from this list?
 
For example, if i add a custom field "myposition", how can i get it in apex class?
UserInfo.getMyposition()  or  UserInfo.myposition  are both invalid.