• mita mukwevho
  • NEWBIE
  • -1 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
global class AssignedRequestsWeeklyEmail implements Schedulable {
    
    public List<Internal_Request__c> InternalRequest {get;set;} 
    public List<Request_User__c> RequestUser {get;set;}
    global void execute(SchedulableContext ctx) {
        // awesome code here
        List<Request_User__c> RequestUser = new List<Request_User__c>();
        boolean blnError = false;
        
        // Create a tasklist that includes all the tasks that are not complete 
        List<Request_User__c> taskList = [SELECT MRG_Request_Management__r.name,name,Assigned_To__c,Assigned_To__r.Email, ownerId, Assigned_Name__c, Assigned_Request_Number__c, 
                                          Request_Category__c, Request_Sub_Category__c, Status__c 
                                          from Request_User__c 
                                          Where Status__c !='Complete'];
        system.debug('tasklist: ' + taskList);
        
        String taskId;
        if(taskList != null){
            system.debug('tasklist is not empty');
            
            Map<string, List<Request_User__c>> RequestsuserToEmail = new Map<string, List<Request_User__c>>();
            Map<string, List<string>> userEmailToRequests = new Map<string, List<string>>();
            //Set<Id> ownerSet = new Set<Id>();
            for(Request_User__c item : taskList) {
                if(!userEmailToRequests.containsKey(item.Assigned_To__r.Email))
                {
                    RequestsuserToEmail.put(item.Assigned_To__r.Email,new list<Request_User__c>());
                    RequestsuserToEmail.get(item.Assigned_To__r.Email).add(item);               
                    userEmailToRequests.put(item.Assigned_To__r.Email,new list<string>());
                    userEmailToRequests.get(item.Assigned_To__r.Email).add(item.MRG_Request_Management__r.name+' '+item.Assigned_Request_Number__c);
                } else {
                    RequestsuserToEmail.get(item.Assigned_To__r.Email).add(item);
                    userEmailToRequests.get(item.Assigned_To__r.Email).add(item.MRG_Request_Management__r.name+' '+item.Assigned_Request_Number__c);
                    
                } 
            }
            system.debug('userEmailToRequests');
            system.debug(userEmailToRequests);
            
            EmailTemplate et=[Select id, subject, body from EmailTemplate where id = '00X6E0000012Y2K' limit 1];
            list<Messaging.SingleEmailMessage> emailToSendList = new list<Messaging.SingleEmailMessage>();
            //LOOP OVER THE MAP KEY!
            for (string key : userEmailToRequests.keySet()) {   
                //List<Request_User__c> reqList = RequestsuserToEmail.get(key);
                List<string> reqList = userEmailToRequests.get(key);
                system.debug('for email address '+key);
                system.debug('we have this list of requests');
                system.debug(reqList);
                integer counter = 1;
                
                string neatReqList='';
                for(string myitem : reqList)
                {
                    neatReqList = neatReqList + counter+'-  '+myitem+'\n';                                        
                    counter++;
                    
                } 
                
                system.debug(neatReqList);
                //BUILD EACH EMAIL USING MAP KEY AND CALLING THE MAP WITH REQUEST USER ITEMS
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[] {'mukwevho.mita1@gmail.com'};
                //mail.setToAddresses(new String[]{key});
                mail.setToAddresses(toAddresses);
                //mail.setSubject('Testing.. Weekly update of open tasks');
                mail.setTargetObjectId(RequestsuserToEmail.get(key)[0].Assigned_To__c);//requires ownerid
                mail.setWhatId(RequestsuserToEmail.get(key)[0].id);//requires id of sobject record
                string emailBody = et.body;
                system.debug('emailBody');
                system.debug(emailBody);
                    emailBody = emailBody.replace('##list##',neatReqList);              
                et.Body=et.Body.replace ('##list##',neatReqList);
                mail.setTemplateId(et.Id);
                //mail.setSenderDisplayName(' Testing.. Assigned Request Weekly Email'); 
               // mail.setSubject('Please find below a list of task assigned to you.');                
                mail.setSaveAsActivity(false);                
                mail.setPlainTextBody(emailBody);               
                emailToSendList.add(mail);
                Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
 

                    }            
                }
            }
    }
Hi guys,

please help,  i just  need a apex code to to the following task and i'm new  salesforce developer..

Weekly emails to be sent out every Monday morning to users that have assigned requests with open statuses.
And i want to use this class to do the work: AssignedRequestsWeeklyEmail. It gets the users with open requests and their Email.
Create the (Email Template / run a report) (investigate what works)
The Email Template must have a list of the assigned users tasks.
There could be one or many tasks.
The user must only get his own requests in the Email.
Send the Email notification to the user. A list of his assigned, open requests.

Please help me  with the code and i will appriciate your help
Hi guys,

please help i just  need a apex code to to the following task and i'm new  salesforce developer..

Weekly emails to be sent out every Monday morning to users that have assigned requests with open statuses.
And i want to use this class to do the work: AssignedRequestsWeeklyEmail. It gets the users with open requests and their Email.
Create the (Email Template / run a report) (investigate what works)
The Email Template must have a list of the assigned users tasks.
There could be one or many tasks.
The user must only get his own requests in the Email.
Send the Email notification to the user. A list of his assigned, open requests.

Please help me  with the code and i will appriciate your help
Hello, I'm trying to make an update on properties on more than a thousand, updating a single field  should automatically update two other related fields. Please show me how do I do this batch Apex class?, because currently it only updates up to 200 records

see below my code

global class FieldValueClonerBatchUpdate implements Database.Batchable<sObject>{

    public String queryStr;  
    public Map<String, String> fieldsMap; 
    
    global FieldValueClonerBatchUpdate (String qry, Map<String, String> clonedFieldsMap){
        this.queryStr = qry;
        this.fieldsMap = clonedFieldsMap;
    }
    
     global List<sObject> start(Database.BatchableContext BC) {
        List<sObject> queryRecords = database.query(queryStr);
         return queryRecords;
    }

    global void execute(Database.BatchableContext BC, List<sobject> scope) {
        List<sObject> sObjsToUpdate = new List<sObject>();
        if (scope.size() > 0) {
            for (sObject sObj : scope) {
                for (String fieldAPIName : fieldsMap.keySet()) {
                    sObj.put(fieldsMap.get(fieldAPIName), sObj.get(fieldAPIName));
                }
                sObjsToUpdate.add(sObj);
            }
            update sObjsToUpdate;
        }
    }   

    global void finish(Database.BatchableContext BC) {
        System.debug('records finished process.');
    }
}
global class AssignedRequestsWeeklyEmail implements Schedulable {
    
    public List<Internal_Request__c> InternalRequest {get;set;} 
    public List<Request_User__c> RequestUser {get;set;}
    global void execute(SchedulableContext ctx) {
        // awesome code here
        List<Request_User__c> RequestUser = new List<Request_User__c>();
        boolean blnError = false;
        
        // Create a tasklist that includes all the tasks that are not complete 
        List<Request_User__c> taskList = [SELECT MRG_Request_Management__r.name,name,Assigned_To__c,Assigned_To__r.Email, ownerId, Assigned_Name__c, Assigned_Request_Number__c, 
                                          Request_Category__c, Request_Sub_Category__c, Status__c 
                                          from Request_User__c 
                                          Where Status__c !='Complete'];
        system.debug('tasklist: ' + taskList);
        
        String taskId;
        if(taskList != null){
            system.debug('tasklist is not empty');
            
            Map<string, List<Request_User__c>> RequestsuserToEmail = new Map<string, List<Request_User__c>>();
            Map<string, List<string>> userEmailToRequests = new Map<string, List<string>>();
            //Set<Id> ownerSet = new Set<Id>();
            for(Request_User__c item : taskList) {
                if(!userEmailToRequests.containsKey(item.Assigned_To__r.Email))
                {
                    RequestsuserToEmail.put(item.Assigned_To__r.Email,new list<Request_User__c>());
                    RequestsuserToEmail.get(item.Assigned_To__r.Email).add(item);               
                    userEmailToRequests.put(item.Assigned_To__r.Email,new list<string>());
                    userEmailToRequests.get(item.Assigned_To__r.Email).add(item.MRG_Request_Management__r.name+' '+item.Assigned_Request_Number__c);
                } else {
                    RequestsuserToEmail.get(item.Assigned_To__r.Email).add(item);
                    userEmailToRequests.get(item.Assigned_To__r.Email).add(item.MRG_Request_Management__r.name+' '+item.Assigned_Request_Number__c);
                    
                } 
            }
            system.debug('userEmailToRequests');
            system.debug(userEmailToRequests);
            
            EmailTemplate et=[Select id, subject, body from EmailTemplate where id = '00X6E0000012Y2K' limit 1];
            list<Messaging.SingleEmailMessage> emailToSendList = new list<Messaging.SingleEmailMessage>();
            //LOOP OVER THE MAP KEY!
            for (string key : userEmailToRequests.keySet()) {   
                //List<Request_User__c> reqList = RequestsuserToEmail.get(key);
                List<string> reqList = userEmailToRequests.get(key);
                system.debug('for email address '+key);
                system.debug('we have this list of requests');
                system.debug(reqList);
                integer counter = 1;
                
                string neatReqList='';
                for(string myitem : reqList)
                {
                    neatReqList = neatReqList + counter+'-  '+myitem+'\n';                                        
                    counter++;
                    
                } 
                
                system.debug(neatReqList);
                //BUILD EACH EMAIL USING MAP KEY AND CALLING THE MAP WITH REQUEST USER ITEMS
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[] {'mukwevho.mita1@gmail.com'};
                //mail.setToAddresses(new String[]{key});
                mail.setToAddresses(toAddresses);
                //mail.setSubject('Testing.. Weekly update of open tasks');
                mail.setTargetObjectId(RequestsuserToEmail.get(key)[0].Assigned_To__c);//requires ownerid
                mail.setWhatId(RequestsuserToEmail.get(key)[0].id);//requires id of sobject record
                string emailBody = et.body;
                system.debug('emailBody');
                system.debug(emailBody);
                    emailBody = emailBody.replace('##list##',neatReqList);              
                et.Body=et.Body.replace ('##list##',neatReqList);
                mail.setTemplateId(et.Id);
                //mail.setSenderDisplayName(' Testing.. Assigned Request Weekly Email'); 
               // mail.setSubject('Please find below a list of task assigned to you.');                
                mail.setSaveAsActivity(false);                
                mail.setPlainTextBody(emailBody);               
                emailToSendList.add(mail);
                Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
 

                    }            
                }
            }
    }
Hello, I'm trying to make an update on properties on more than a thousand, updating a single field  should automatically update two other related fields. Please show me how do I do this batch Apex class?, because currently it only updates up to 200 records

see below my code

global class FieldValueClonerBatchUpdate implements Database.Batchable<sObject>{

    public String queryStr;  
    public Map<String, String> fieldsMap; 
    
    global FieldValueClonerBatchUpdate (String qry, Map<String, String> clonedFieldsMap){
        this.queryStr = qry;
        this.fieldsMap = clonedFieldsMap;
    }
    
     global List<sObject> start(Database.BatchableContext BC) {
        List<sObject> queryRecords = database.query(queryStr);
         return queryRecords;
    }

    global void execute(Database.BatchableContext BC, List<sobject> scope) {
        List<sObject> sObjsToUpdate = new List<sObject>();
        if (scope.size() > 0) {
            for (sObject sObj : scope) {
                for (String fieldAPIName : fieldsMap.keySet()) {
                    sObj.put(fieldsMap.get(fieldAPIName), sObj.get(fieldAPIName));
                }
                sObjsToUpdate.add(sObj);
            }
            update sObjsToUpdate;
        }
    }   

    global void finish(Database.BatchableContext BC) {
        System.debug('records finished process.');
    }
}
Hello, I got a question for retriving data. For example, if I use code like this: <apex:outputtext value="{!Case.Owner.Name}" /> and I can get a text show on my web page. But how can I know where does each value after dot come from, is that simply (object name) . (field name) . (data wanna retrive). But how can I know the exact name of data that I wanna retrive?  The example I showed is a bad example, cuz I assume that the name of data I wanna retrive maybe call Name, yet I dont know where to find it.     Thanks for helping.