• carmilyn.c martin
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 15
    Replies
Hello, 

I need to create a batch class that will schedule to run every Friday that will automatically approve Items that are pending from Rep's Approval so that it will proceed to the next level of approver which is their managers, my code is not working here is my code: 

global class PTMS_autoApproveRepBatchable implements Database.batchable<sObject>, Database.Stateful {

    global Iterable<sObject> start(Database.BatchableContext info) {
        return Database.getQueryLocator(
            [Select Id, Auto_Approval__c FROM Professional_Target_List_Line_Item_esi__c WHERE Rep_Approval__c = True AND Proposed_Rep_Approval_Status__c = 'Pending' AND Id = 'a203F000000H0noQAC']);
    }

    global void execute(Database.BatchableContext info, List<Professional_Target_List_Line_Item_esi__c> pendPTLI){
        system.debug('Ming'+ pendPTLI.size());
        Set<Id> pendingRepPTLIset = new Set<Id>();
        List<Professional_Target_List_Line_Item_esi__c> ptliToUpdate = new List<Professional_Target_List_Line_Item_esi__c>();
            
        for(Professional_Target_List_Line_Item_esi__c pendingRepPTLI : pendPTLI){
                pendingRepPTLI.Auto_Approval__c = True;
                ptliToUpdate.add(pendingRepPTLI);
                pendingRepPTLIset.add(pendingRepPTLI.Id); 
                system.debug('Ming2'+ pendingRepPTLIset);
        }
                try {
                    update ptliToUpdate;
                    }
                    
                catch(DmlException e){
                    System.debug('exception caught :' + e.getMessage());    
                    }
        
                Approval.ProcessWorkitemRequest[] prWkItems = New Approval.ProcessWorkItemRequest[]{};
                ProcessInstance[] pi = [Select ID, Status, TargetObject.Name,
                (SELECT Id, ActorId, ProcessInstanceId FROM Workitems),
                (SELECT Id, StepStatus, Comments FROM Steps) From ProcessInstance
                Where TargetObjectID IN :pendingRepPTLIset AND Status = 'Pending'];
                
                for(ProcessInstance instance : pi){
                    for(ProcessInstanceWorkItem workItem : instance.WorkItems){
                        Approval.ProcessWorkitemRequest prWkItem = new Approval.ProcessWorkitemRequest();
                        prWkItem.setWorkItemID(workItem.id);
                        prWkItem.setAction('Approve');
                        prWkItems.add(prWkItem);
                    }
                }         
            
    }
    global void finish(Database.BatchableContext info){   
    }
  
}
hello, 

We have a process builder created that will fire if a new record is created and the action is to create another Action and the to send an email. Since we need to cc the managers we created an @invocablemethod and incorporate the Email Template we created the email is being sent however, the merge fields are all blank. Here is our Apex Class: 

public class SendEmailToRep_CcDMs{

    @InvocableMethod
    public static void GetUserRoleId(List<Id> proposedTerritory)
    {   
        string tempName = 'DS_Proposing_NICM_Tgt_Account';
        List<PTMS_Users_and_Role__c> userManager = [SELECT Id,Name,Manager__c,User__c,Manager__r.Email,User__r.Email,User__r.Id 
                                                    FROM PTMS_Users_and_Role__c 
                                                    WHERE Id IN:proposedTerritory];
                                                    
        Id templateId; 
        templateId = [select id, name from EmailTemplate where developername = :tempName].id;                                            
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        
                    for(PTMS_Users_and_Role__c ptmsUsers: userManager){
                            
                            
                                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                                    
                                    //Send email to Rep
                                    /*List<String> sendTo = new List<String>();
                                    sendTo.add(ptmsUsers.User__r.Email);
                                    mail.setToAddresses(sendTo); */
                                    
                                    mail.setSenderDisplayName('Vector Team');
                                    mail.setTargetObjectId(ptmsUsers.User__r.Id);
                                    mail.setTemplateId(templateId);
                                    mail.setSaveAsActivity(false);
    
                                    //cc Manager
                                    List<String> ccTo = new List<String>();
                                    ccTo.add(ptmsUsers.Manager__r.Email);
                                    mail.setCcAddresses(ccTo);
                                                                     
                                    mails.add(mail);
                    }
                    Messaging.sendEmail(mails);
    }//end of method
}//end of class

Please help. 

Thank you. 

 
Hello, 

I have a custom object "Professional Target List Items" and on that custom object, i added a custom button that will direct you to the edit page pop of the record, so instead of "Edit" button, this new Button is now visible. 

We also have a VF Page that list all Record on Professional Target List Items object. 

User-added image

I need to add the custom button to the column highlighted for each records listed so our users will be directed to the edit page pop up of the Record. 

Thank you.

Ming
Hello, 

I am having trouble running a batch class and I am encountering an error "First error: Too many DML rows: 10001". 

Here is the query and the batch class I am running on Dev Console: 

String query='Select Network_Name__c,Network_ID__c, Hub_Account__c from Account where Hub_Account__c !=NULL AND Network_Name__c !=NULL AND Network_ID__c !=NULL';
Id batchInstanceId = Database.executeBatch(new Batchable_Eisai_CrtTarget_Opn(query),200);

Need some help. Thank you.

Ming
Hi,

I am creating a trigger where  it will only fire if the user matches these criteria:(fields from user object)

1. Global_ID__c like 'esi1%'
2. Profile.Name != 'System_Admin'

Here is my trigger. 

trigger Time_Off_Terrirtory_more_than_90_days_old on Time_Off_Territory_vod__c (before delete,before insert,before update){
    
    if(Trigger.isDelete)
        {
        for(Time_Off_Territory_vod__c tot: trigger.old)
            if((tot.Date_vod__c < (system.today()- 90 )) && tot.Admin__c != True )
                {
                tot.adderror('You cannot delete or cancel Paid Time Off record that is 90 or more days old.' );
                }   
            else if((Date.today() > Date.NewInstance(Date.today().year(), 1, 10)) && (tot.Date_vod__c < Date.NewInstance(Date.today().year(), 1, 1)) && tot.Admin__c != True)
                {
                tot.adderror('You cannot delete or cancel Time Off Entry Record of Last Fiscal Year' );
                }  
        }
    
    if (Trigger.isInsert)
        {
        for(Time_Off_Territory_vod__c tot: trigger.new)
            if(
                (tot.Date_vod__c < Date.NewInstance(Date.today().year(), 1, 1)) 
                && 
                ( system.today() > Date.NewInstance(Date.today().year(), 1, 10)) 
                && 
                (tot.Admin__c != True)
               )
            {
            tot.adderror('Error4');    
            }
        }
    }
 
 
Hello, 

This is my Trigger and I am receiving an error when I am editing a Record:

trigger Eisai_Send_Email_Notification_End_Of_Fiscal_Year on PTO_esi__c(after update){
    List<String> sendToRep_List = new List<String>();
    List<String> sendToDM_List = new List<String>();
    String emailTemplateIdRep = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Email_Template_PTO_Year_End_Notification_Rep'].Id;
    String emailTemplateIdDM = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Email_Template_PTO_Year_End_Notification_DM'].Id;
    
    for(PTO_esi__c tpto: [SELECT Owner_Email__c,ID FROM PTO_esi__c WHERE Type_of_User__c = 'REP'])
        {
        sendToRep_List.add(tpto.Owner_Email__c);
        }
    for(PTO_esi__c tpto: [SELECT Owner_Email__c,ID FROM PTO_esi__c WHERE Type_of_User__c = 'DM'])
        {
        sendToDM_List.add(tpto.Owner_Email__c);
        }
    
    for(PTO_esi__c pto: trigger.new){
        
        if(pto.Active__c && pto.Current_user_Level__c == 'REP')
            {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setToAddresses(sendToRep_List);
            mail.setTemplateId(emailTemplateIdRep);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
            }
            
        if(pto.Active__c && pto.Current_user_Level__c == 'DM')
            {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setToAddresses(sendToDM_List);
            mail.setTemplateId(emailTemplateIdDM);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
            }
    }

}




ERROR Message: 
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Eisai_Send_Email_Notification_End_Of_Fiscal_Year caused an unexpected exception, contact your administrator: Eisai_Send_Email_Notification_End_Of_Fiscal_Year: execution of AfterUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing targetObjectId with template: []: Trigger.Eisai_Send_Email_Notification_End_Of_Fiscal_Year: line 31, column 1

I am editing a record with value on this field (Current_user_Level__c ) = DM
and setting Active checkbox to true. 

Thank you. 
I need to create a trigger where (tot.Date_vod__c < (THIS_YEAR(system.today())-1-11))

I want to avoid users from deleting TOT with Date_vod__c that is less than Jan 11 of this year
I am not sure if I am doing it correctly.
Hello, 

I would like to avoid our users from creating PTO records with pto_date__c of January 10 onwards (of next year). PTO Records of current year is only counted if pto_date__c is within January 11 (current Year) until January 10 of next year.

I would also like to avoid them deleting these PTO records. They cannot delete their PTO records with pto_date__c from January 11 (last Year) to january 10 of this year. 

I am not sure how to do this. 

We have 2 Fields from Custom Object Letter Request
1. Product_esi__c  - picklist Field
2. Item_esi__c - picklist field

We need to get their values from Call Sample Object and the field that is involved is a lookup field to Product Object.
2. Product_vod__c  - lookup

We have a trigger that creates Letter Request Record where these fields "Product_esi__c" and "Item_esi__c" from Letter Request Object will be populated with value from "Product_vod__c" field of Call Sample Object

- Product_esi__c = this will get its value from "Product_vod__c"'s Parent Product Name Field (Need to know how I can get the Name of the Parent Product of this child record "Product_vod__c".)
- Item_esi__c = this will get its value from "Product_vod__c"'s Name (with the current trigger it is getting the Salesforce ID of the Product instead of the name of the Product)


Current TRIGGER: 

List<Letter_Request_esi__c> insertLetterRequestList = New List<Letter_Request_esi__c>();
List<Letter_Request_esi__c> deleteLetterRequestList = New List<Letter_Request_esi__c>();
Set<Id> delCallSampleIds = New Set<Id>();
if(Trigger.IsInsert)
{
    system.debug('***********Enter if IsInsert****************');
    for(Call2_Sample_vod__c cs : trigger.New)
    {
        system.debug('***********iterating all call Sample records****************');
        if(cs.Product_Type_esi__c != null && cs.Product_Type_esi__c == 'Letter')
        {
            system.debug('***********Enter if product is null and prodcut type is Letter****************');
            Letter_Request_esi__c letReq = New Letter_Request_esi__c(Call__c = cs.Call2_Vod__c, Call_Sample__c = cs.id , Account__c = cs.Account_vod__c, Item_esi__c = cs.Product_vod__c , Product_Type__c = 'Letter Request' );
            insertLetterRequestList.add(letReq);
        }
        else if(cs.Product_Type_esi__c != null && cs.Product_Type_esi__c == 'Promotional')
        {
            system.debug('***********Enter if product is null and prodcut type is Promotional Letter****************');
            Letter_Request_esi__c letReq = New Letter_Request_esi__c(Call__c = cs.Call2_Vod__c, Call_Sample__c = cs.id , Account__c = cs.Account_vod__c, Item_esi__c = cs.Product_vod__c , Product_Type__c = 'Promotional Item');
            insertLetterRequestList.add(letReq);



WHAT We have before was: This didn't work


List<Letter_Request_esi__c> insertLetterRequestList = New List<Letter_Request_esi__c>();
List<Letter_Request_esi__c> deleteLetterRequestList = New List<Letter_Request_esi__c>();
Set<Id> delCallSampleIds = New Set<Id>();
if(Trigger.IsInsert)
{
    system.debug('***********Enter if IsInsert****************');
    for(Call2_Sample_vod__c cs : trigger.New)
    {
        system.debug('***********iterating all call Sample records****************');
        if(cs.Product_Type_esi__c != null && cs.Product_Type_esi__c == 'Letter')
        {
            system.debug('***********Enter if product is null and prodcut type is Letter****************');
            Letter_Request_esi__c letReq = New Letter_Request_esi__c(Call__c = cs.Call2_Vod__c, Call_Sample__c = cs.id , Account__c = cs.Account_vod__c, Item_esi__c = cs.Product_vod__r.Name , Product_Type__c = 'Letter Request' , Product_esi__c = cs.Product_vod__r.Parent_Product_vod__r.Name);
            insertLetterRequestList.add(letReq);
        }
        else if(cs.Product_Type_esi__c != null && cs.Product_Type_esi__c == 'Promotional')
        {
            system.debug('***********Enter if product is null and prodcut type is Promotional Letter****************');
            Letter_Request_esi__c letReq = New Letter_Request_esi__c(Call__c = cs.Call2_Vod__c, Call_Sample__c = cs.id , Account__c = cs.Account_vod__c, Item_esi__c = cs.Product_vod__r.Name , Product_Type__c = 'Promotional Item' , Product_esi__c = cs.Product_vod__r.Parent_Product_vod__r.Name);
            insertLetterRequestList.add(letReq);
        }
 
I am trying to edit an existing trigger to get values of Coaching Report Object from Monthly PC Territory IC Object but i encountered an error when i tried to use it:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Eisai_UpdateMonthlyWeeklyTransValuesOnFCR_Trg caused an unexpected exception, contact your administrator: Eisai_UpdateMonthlyWeeklyTransValuesOnFCR_Trg: execution of BeforeInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Monthly_PC_Territory_IC_esi__c.Aricept_Tgt_QTD_Ter_Pct_Atnment__c: Trigger.Eisai_UpdateMonthlyWeeklyTransValuesOnFCR_Trg: line 157, column 1

Here is my trigger:

trigger Eisai_UpdateMonthlyWeeklyTransValuesOnFCR_Trg on Coaching_Report_vod__c(before Insert) {
    Set<Id> userIds = New Set<Id>();
    Map<Id,Id> userTerrMap = New Map<Id,Id>();
    Map<Id,Territory> terrMap = New Map<Id,Territory>();
    Map<String,Monthly_PC_Territory_IC_esi__c> terrMonPcTerr = New Map<String,Monthly_PC_Territory_IC_esi__c>();
    Map<String,Monthly_ONC_Territory_IC_esi__c> terrMonOnTerr = New Map<String,Monthly_ONC_Territory_IC_esi__c>();
    Map<String,Monthly_PC_Territory_TRx_esi__c> terrMonPcTrxTerr = New Map<String,Monthly_PC_Territory_TRx_esi__c>();
    Map<String,Weekly_ONC_Territory_Sales_esi__c> weekONCTerrSales = New Map<String,Weekly_ONC_Territory_Sales_esi__c>();
    Map<String,Weekly_PC_Call_Averages_esi__c> weekPCCalAvg = New Map<String,Weekly_PC_Call_Averages_esi__c>();
    Map<String,Weekly_ONC_Call_Averages_esi__c> weekONCCalAvg = New Map<String,Weekly_ONC_Call_Averages_esi__c>();
    set<String> terrNames = New Set<String>();
    //Added by Cognizant on Jun 24th 2013
    Map<String,Weekly_PC_Territory_TRx_NBRx__c> terrWkPcTerr = New Map<String,Weekly_PC_Territory_TRx_NBRx__c>();
    Map<String,Weekly_PC_Territory_Banzel_TRx_NBRx__c> terrWkPcBanzlTerr = New Map<String,Weekly_PC_Territory_Banzel_TRx_NBRx__c>();
    Map<String,Monthly_MB_Territory_IC_esi__c> terrMonMbBelvqTerr = New Map<String,Monthly_MB_Territory_IC_esi__c>();
    //added by cognizant on 7/7/2014 PD
    Map<String,Weekly_EP_Territory_TRx_NBRx__c> terrWkEPTerr = New Map<String,Weekly_EP_Territory_TRx_NBRx__c>();
    
    /********************Code to update Rep Name**********************/
    if(Eisai_CaseMedicalInqGlobalVariable_Cls.isUpdateRepName)
    {
        List<Id> empIds=new List<Id>();
        Set<Id> terrIds = new Set<Id>();
        List<UserTerritory> repuserterr = New List<UserTerritory>();
        Territory terrName = New Territory();
        for(Coaching_Report_vod__c c:Trigger.New)
        {
            if(c.Employee_vod__c !=null)
                empIds.add(c.Employee_vod__c);
        } 
        empIds.add(userinfo.getUserId());  
        repuserterr = [select UserId,TerritoryId from UserTerritory where UserId in: empIds];
        Map<id,id> territoryMap = New Map<Id,Id>();
        Map<id,String> territoryIndicatorMap = New Map<Id,String>();
        for(UserTerritory ut : repuserterr)
        {
            territoryMap.put(ut.userId,ut.TerritoryId);
            terrIds.add(ut.TerritoryId);
        }
        List<Territory> terrIndicatorList = New List<Territory>();
        if(terrIds.size()>0)
        {
            terrIndicatorList = [select Id,Territory_Indicator_esi__c from Territory where id in : terrIds];
        }
        for(Territory t : terrIndicatorList)
        {
            territoryIndicatorMap.put(t.Id,t.Territory_Indicator_esi__c);
        }
        for(Coaching_Report_vod__c c:Trigger.New)
        {
            if(c.Employee_vod__c != null)
            {
                if(territoryMap.containsKey(c.Employee_vod__c))
                {
                    if(territoryIndicatorMap.containsKey(territoryMap.get(c.Employee_vod__c)))
                    {
                        if('T' != territoryIndicatorMap.get(territoryMap.get(c.Employee_vod__c)))
                            c.addError('Select valid Representative Name');
                    }
                    else
                        c.addError('Select valid Representative Name');   
                } 
                else
                    c.addError('Select valid Representative Name');        
            }
            if(c.Employee_vod__c == null)
            {
                if(territoryMap.containsKey(userinfo.getUserId()))
                {
                    if('T' == territoryIndicatorMap.get(territoryMap.get(userinfo.getUserId())))
                    {
                        c.Employee_vod__c = userinfo.getUserId();
                    }
                    else
                        c.addError('Select valid Representative Name'); 
                }
                else
                    c.addError('Territory is not defined for Current User'); 
            }
            /*if(c.Manager_vod__c == null)
            {
                if(territoryMap.containsKey(userinfo.getUserId()))
                {
                    if('D' == territoryIndicatorMap.get(territoryMap.get(c.Manager_vod__c)))
                    {
                        c.Employee_vod__c = userinfo.getUserId();
                    }
                }
            }*/
    
        }
        Eisai_CaseMedicalInqGlobalVariable_Cls.isUpdateRepName = false;
        if(terrIds.size()>0)
            terrIds.clear();
        if(empIds.size()>0)
            empIds.clear();
     }
    /*****End for updating Rep name***************/
    for(Coaching_Report_vod__c cp:Trigger.New)
    {
        system.debug('***************Collecting Employee Ids*************');
        if(cp.Employee_vod__c !=null)
            userIds.add(cp.Employee_vod__c);
    }
    if(userIds.size()>0)
        constructTerrmap(userIds);
    for(Coaching_Report_vod__c cp:Trigger.New)
    {
        if(cp.Employee_vod__c != null && userTerrMap.ContainsKey(cp.Employee_vod__c ))
        {
            system.debug('***************Updating Terriotry Number and Division fields*************');
            cp.Territory_Number_esi__c = terrMap.get(userTerrMap.get(cp.Employee_vod__c)).Name;
            cp.Division_esi__c = terrMap.get(userTerrMap.get(cp.Employee_vod__c)).Division_esi__c;
        }
    } 
    for(Coaching_Report_vod__c cp:Trigger.New)
    {           
        if(cp.Territory_Number_esi__c != null)
                terrNames.add(cp.Territory_Number_esi__c);
    }        
    if(terrNames.size()>0)
        constructMaps(terrNames);
    for(Coaching_Report_vod__c cp:Trigger.New)
    {
        system.debug('***************Mapping for Monthly PC territory values*************');
        if(cp.Territory_Number_esi__c != null && terrMonPcTerr.ContainsKey(cp.Territory_Number_esi__c))
        {
            system.debug('*Aricept_Total_QTD_Territory_Goal__c*' + terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Total_QTD_Territory_Goal__c);        
            /*OldCode cp.Aciphex_QTD_Territory_Goal_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aciphex_QTD_Territory_Goal__c;*/
            cp.Aricept_Total_QTD_Territory_Goal_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Total_QTD_Territory_Goal__c;
            
            /*OldCode cp.Aciphex_QTD_Territory_Sales_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aciphex_QTD_Territory_TRx__c;*/
            cp.Aricept_Total_QTD_Territory_Volume_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Total_QTD_Territory_Volume__c;
            
            /*OldCode cp.Aricept_QTD_Territory_Goal_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_QTD_Territory_Goal__c;*/
            cp.Aricept_Target_QTD_Territory_Goal_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Target_QTD_Territory_Goal__c;
            
            
            /*OldCode cp.Aricept_QTD_Territory_Sales_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_QTD_Territory_TRx__c;*/
            cp.Aricept_Target_QTD_Territory_Volume_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Target_QTD_Territory_Volume__c ;
            
            
            /*OldCode cp.Banzel_QTD_Territory_Goal_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Banzel_QTD_Territory_Goal__c;*/
            cp.Aciphex_QTD_Territory_Goal_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aciphex_QTD_Territory_Goal__c;
            
            /*OldCode cp.Banzel_QTD_Territory_Sales_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Banzel_QTD_Territory_TRx__c;*/
            cp.Aciphex_QTD_Territory_Volume_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aciphex_QTD_Territory_Volume__c;
            
            /*OldCode cp.Pct_IC_Attainment_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).IC_Percent_Attainment_QTD__c;*/
            /*OldCode cp.IC_Rank_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).IC_Rank_QTD__c;*/
            
            cp.Banzel_QTD_Territory_Attainment__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Tgt_QTD_Ter_Pct_Atnment__c;
            cp.Banzel_QTD_Territory_Goal__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Target_QTD_Territory_Goal__c;
            cp.Banzel_QTD_Territory_Volume__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Target_QTD_Territory_Volume__c;
            cp.Fycompa_Prev_Qtr_Avg_Monthly_TRx__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Total_QTD_Territory_Goal__c;
            cp.Fycompa_QTD_Avg_Monthly_TRx__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Total_QTD_Territory_Volume__c;
            cp.Fycompa_QTD_TRx_to_Baseline__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Tot_QTD_Ter_Pct_Attainment__c;
            cp.As_Of_Banzel_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Data_As_Of__c;


NOTE: Line 157 starts here:  cp.Banzel_QTD_Territory_Attainment__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Tgt_QTD_Ter_Pct_Atnment__c;
            cp.Banzel_QTD_Territory_Goal__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Target_QTD_Territory_Goal__c;
            cp.Banzel_QTD_Territory_Volume__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Target_QTD_Territory_Volume__c;
            cp.Fycompa_Prev_Qtr_Avg_Monthly_TRx__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Total_QTD_Territory_Goal__c;
            cp.Fycompa_QTD_Avg_Monthly_TRx__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Total_QTD_Territory_Volume__c;
            cp.Fycompa_QTD_TRx_to_Baseline__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Aricept_Tot_QTD_Ter_Pct_Attainment__c;
            cp.As_Of_Banzel_esi__c = terrMonPcTerr.get(cp.Territory_Number_esi__c).Data_As_Of__c;
We have a scheduled job that runs every 6am but we received this error: "First error: Invalid id:"

Apex Class: Eisai_HCPMail_Batchable_Cls

global class Eisai_HCPMail_Batchable_Cls implements Database.Batchable<sObject>
{
    global final String Query;
    global Eisai_HCPMail_Batchable_Cls(String q)
    {
        Query=q;   
    }             
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        System.Debug('#######Start method called');
        return Database.getQueryLocator(query);
   }
   global void execute(Database.BatchableContext BC,List<sObject> scope)
   {
        System.Debug('#######executeCalled');
        System.Debug('#######callsamplesList'+scope);
        Eisai_TaskHelper_Cls obj = new Eisai_TaskHelper_Cls (); 
        //obj.SendmailtoHCP_forBatch(scope);
        obj.sendHcpCntatdBatchMail(scope);
   }//end of execute
   global void finish(Database.BatchableContext BC)
   {

   }

}//end of batch class


Another Apex Class: 

global Class Eisai_HCPMail_Schedule_Cls implements Schedulable {
public String query; 
global void execute(SchedulableContext sc)
{
 System.Debug('@@@@@@SchedulerCalled');


      query='Select '+
            'Assigned_To_esi__c,Task_Owner_Profile__c,Assign_To_Med_Comm_esi__c,Assign_User_Email__c,HCP_Contacted_Date_esi__c,  '+
            'HCP_Contacted_esi__c,HCP_Contacted_text__c,OwnerId,No_of_Reminder_eMails_esi__c,whoId,Number_of_Days_to_Contact_esi__c '+ 
            'from Task '+
            'WHERE HCP_Contacted_esi__c =false '+
            'and Is_HCP_enable_esi__c =true '+
            'and Number_of_Days_to_Contact_value__c > 3 '+
            'and No_of_Reminder_eMails_esi__c < 3 '+
      //      'and OwnerId=\'005A0000002KfY1\''+
          ' and Status !=\'Completed\''+
            ' and Request_Type_esi__c =\'MSL Request\'';

Id batchInstanceId = Database.executeBatch(new Eisai_HCPMail_Batchable_Cls(query),5);  

}
}
Hello, 

I need to create a batch class that will schedule to run every Friday that will automatically approve Items that are pending from Rep's Approval so that it will proceed to the next level of approver which is their managers, my code is not working here is my code: 

global class PTMS_autoApproveRepBatchable implements Database.batchable<sObject>, Database.Stateful {

    global Iterable<sObject> start(Database.BatchableContext info) {
        return Database.getQueryLocator(
            [Select Id, Auto_Approval__c FROM Professional_Target_List_Line_Item_esi__c WHERE Rep_Approval__c = True AND Proposed_Rep_Approval_Status__c = 'Pending' AND Id = 'a203F000000H0noQAC']);
    }

    global void execute(Database.BatchableContext info, List<Professional_Target_List_Line_Item_esi__c> pendPTLI){
        system.debug('Ming'+ pendPTLI.size());
        Set<Id> pendingRepPTLIset = new Set<Id>();
        List<Professional_Target_List_Line_Item_esi__c> ptliToUpdate = new List<Professional_Target_List_Line_Item_esi__c>();
            
        for(Professional_Target_List_Line_Item_esi__c pendingRepPTLI : pendPTLI){
                pendingRepPTLI.Auto_Approval__c = True;
                ptliToUpdate.add(pendingRepPTLI);
                pendingRepPTLIset.add(pendingRepPTLI.Id); 
                system.debug('Ming2'+ pendingRepPTLIset);
        }
                try {
                    update ptliToUpdate;
                    }
                    
                catch(DmlException e){
                    System.debug('exception caught :' + e.getMessage());    
                    }
        
                Approval.ProcessWorkitemRequest[] prWkItems = New Approval.ProcessWorkItemRequest[]{};
                ProcessInstance[] pi = [Select ID, Status, TargetObject.Name,
                (SELECT Id, ActorId, ProcessInstanceId FROM Workitems),
                (SELECT Id, StepStatus, Comments FROM Steps) From ProcessInstance
                Where TargetObjectID IN :pendingRepPTLIset AND Status = 'Pending'];
                
                for(ProcessInstance instance : pi){
                    for(ProcessInstanceWorkItem workItem : instance.WorkItems){
                        Approval.ProcessWorkitemRequest prWkItem = new Approval.ProcessWorkitemRequest();
                        prWkItem.setWorkItemID(workItem.id);
                        prWkItem.setAction('Approve');
                        prWkItems.add(prWkItem);
                    }
                }         
            
    }
    global void finish(Database.BatchableContext info){   
    }
  
}
Hello, 

I am having trouble running a batch class and I am encountering an error "First error: Too many DML rows: 10001". 

Here is the query and the batch class I am running on Dev Console: 

String query='Select Network_Name__c,Network_ID__c, Hub_Account__c from Account where Hub_Account__c !=NULL AND Network_Name__c !=NULL AND Network_ID__c !=NULL';
Id batchInstanceId = Database.executeBatch(new Batchable_Eisai_CrtTarget_Opn(query),200);

Need some help. Thank you.

Ming
Hi,

I am creating a trigger where  it will only fire if the user matches these criteria:(fields from user object)

1. Global_ID__c like 'esi1%'
2. Profile.Name != 'System_Admin'

Here is my trigger. 

trigger Time_Off_Terrirtory_more_than_90_days_old on Time_Off_Territory_vod__c (before delete,before insert,before update){
    
    if(Trigger.isDelete)
        {
        for(Time_Off_Territory_vod__c tot: trigger.old)
            if((tot.Date_vod__c < (system.today()- 90 )) && tot.Admin__c != True )
                {
                tot.adderror('You cannot delete or cancel Paid Time Off record that is 90 or more days old.' );
                }   
            else if((Date.today() > Date.NewInstance(Date.today().year(), 1, 10)) && (tot.Date_vod__c < Date.NewInstance(Date.today().year(), 1, 1)) && tot.Admin__c != True)
                {
                tot.adderror('You cannot delete or cancel Time Off Entry Record of Last Fiscal Year' );
                }  
        }
    
    if (Trigger.isInsert)
        {
        for(Time_Off_Territory_vod__c tot: trigger.new)
            if(
                (tot.Date_vod__c < Date.NewInstance(Date.today().year(), 1, 1)) 
                && 
                ( system.today() > Date.NewInstance(Date.today().year(), 1, 10)) 
                && 
                (tot.Admin__c != True)
               )
            {
            tot.adderror('Error4');    
            }
        }
    }
 
 
Hello, 

This is my Trigger and I am receiving an error when I am editing a Record:

trigger Eisai_Send_Email_Notification_End_Of_Fiscal_Year on PTO_esi__c(after update){
    List<String> sendToRep_List = new List<String>();
    List<String> sendToDM_List = new List<String>();
    String emailTemplateIdRep = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Email_Template_PTO_Year_End_Notification_Rep'].Id;
    String emailTemplateIdDM = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Email_Template_PTO_Year_End_Notification_DM'].Id;
    
    for(PTO_esi__c tpto: [SELECT Owner_Email__c,ID FROM PTO_esi__c WHERE Type_of_User__c = 'REP'])
        {
        sendToRep_List.add(tpto.Owner_Email__c);
        }
    for(PTO_esi__c tpto: [SELECT Owner_Email__c,ID FROM PTO_esi__c WHERE Type_of_User__c = 'DM'])
        {
        sendToDM_List.add(tpto.Owner_Email__c);
        }
    
    for(PTO_esi__c pto: trigger.new){
        
        if(pto.Active__c && pto.Current_user_Level__c == 'REP')
            {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setToAddresses(sendToRep_List);
            mail.setTemplateId(emailTemplateIdRep);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
            }
            
        if(pto.Active__c && pto.Current_user_Level__c == 'DM')
            {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setToAddresses(sendToDM_List);
            mail.setTemplateId(emailTemplateIdDM);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
            }
    }

}




ERROR Message: 
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Eisai_Send_Email_Notification_End_Of_Fiscal_Year caused an unexpected exception, contact your administrator: Eisai_Send_Email_Notification_End_Of_Fiscal_Year: execution of AfterUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing targetObjectId with template: []: Trigger.Eisai_Send_Email_Notification_End_Of_Fiscal_Year: line 31, column 1

I am editing a record with value on this field (Current_user_Level__c ) = DM
and setting Active checkbox to true. 

Thank you. 
I need to create a trigger where (tot.Date_vod__c < (THIS_YEAR(system.today())-1-11))

I want to avoid users from deleting TOT with Date_vod__c that is less than Jan 11 of this year
I am not sure if I am doing it correctly.
Hello, 

I would like to avoid our users from creating PTO records with pto_date__c of January 10 onwards (of next year). PTO Records of current year is only counted if pto_date__c is within January 11 (current Year) until January 10 of next year.

I would also like to avoid them deleting these PTO records. They cannot delete their PTO records with pto_date__c from January 11 (last Year) to january 10 of this year. 

I am not sure how to do this. 

We have 2 Fields from Custom Object Letter Request
1. Product_esi__c  - picklist Field
2. Item_esi__c - picklist field

We need to get their values from Call Sample Object and the field that is involved is a lookup field to Product Object.
2. Product_vod__c  - lookup

We have a trigger that creates Letter Request Record where these fields "Product_esi__c" and "Item_esi__c" from Letter Request Object will be populated with value from "Product_vod__c" field of Call Sample Object

- Product_esi__c = this will get its value from "Product_vod__c"'s Parent Product Name Field (Need to know how I can get the Name of the Parent Product of this child record "Product_vod__c".)
- Item_esi__c = this will get its value from "Product_vod__c"'s Name (with the current trigger it is getting the Salesforce ID of the Product instead of the name of the Product)


Current TRIGGER: 

List<Letter_Request_esi__c> insertLetterRequestList = New List<Letter_Request_esi__c>();
List<Letter_Request_esi__c> deleteLetterRequestList = New List<Letter_Request_esi__c>();
Set<Id> delCallSampleIds = New Set<Id>();
if(Trigger.IsInsert)
{
    system.debug('***********Enter if IsInsert****************');
    for(Call2_Sample_vod__c cs : trigger.New)
    {
        system.debug('***********iterating all call Sample records****************');
        if(cs.Product_Type_esi__c != null && cs.Product_Type_esi__c == 'Letter')
        {
            system.debug('***********Enter if product is null and prodcut type is Letter****************');
            Letter_Request_esi__c letReq = New Letter_Request_esi__c(Call__c = cs.Call2_Vod__c, Call_Sample__c = cs.id , Account__c = cs.Account_vod__c, Item_esi__c = cs.Product_vod__c , Product_Type__c = 'Letter Request' );
            insertLetterRequestList.add(letReq);
        }
        else if(cs.Product_Type_esi__c != null && cs.Product_Type_esi__c == 'Promotional')
        {
            system.debug('***********Enter if product is null and prodcut type is Promotional Letter****************');
            Letter_Request_esi__c letReq = New Letter_Request_esi__c(Call__c = cs.Call2_Vod__c, Call_Sample__c = cs.id , Account__c = cs.Account_vod__c, Item_esi__c = cs.Product_vod__c , Product_Type__c = 'Promotional Item');
            insertLetterRequestList.add(letReq);



WHAT We have before was: This didn't work


List<Letter_Request_esi__c> insertLetterRequestList = New List<Letter_Request_esi__c>();
List<Letter_Request_esi__c> deleteLetterRequestList = New List<Letter_Request_esi__c>();
Set<Id> delCallSampleIds = New Set<Id>();
if(Trigger.IsInsert)
{
    system.debug('***********Enter if IsInsert****************');
    for(Call2_Sample_vod__c cs : trigger.New)
    {
        system.debug('***********iterating all call Sample records****************');
        if(cs.Product_Type_esi__c != null && cs.Product_Type_esi__c == 'Letter')
        {
            system.debug('***********Enter if product is null and prodcut type is Letter****************');
            Letter_Request_esi__c letReq = New Letter_Request_esi__c(Call__c = cs.Call2_Vod__c, Call_Sample__c = cs.id , Account__c = cs.Account_vod__c, Item_esi__c = cs.Product_vod__r.Name , Product_Type__c = 'Letter Request' , Product_esi__c = cs.Product_vod__r.Parent_Product_vod__r.Name);
            insertLetterRequestList.add(letReq);
        }
        else if(cs.Product_Type_esi__c != null && cs.Product_Type_esi__c == 'Promotional')
        {
            system.debug('***********Enter if product is null and prodcut type is Promotional Letter****************');
            Letter_Request_esi__c letReq = New Letter_Request_esi__c(Call__c = cs.Call2_Vod__c, Call_Sample__c = cs.id , Account__c = cs.Account_vod__c, Item_esi__c = cs.Product_vod__r.Name , Product_Type__c = 'Promotional Item' , Product_esi__c = cs.Product_vod__r.Parent_Product_vod__r.Name);
            insertLetterRequestList.add(letReq);
        }
 
We have a scheduled job that runs every 6am but we received this error: "First error: Invalid id:"

Apex Class: Eisai_HCPMail_Batchable_Cls

global class Eisai_HCPMail_Batchable_Cls implements Database.Batchable<sObject>
{
    global final String Query;
    global Eisai_HCPMail_Batchable_Cls(String q)
    {
        Query=q;   
    }             
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        System.Debug('#######Start method called');
        return Database.getQueryLocator(query);
   }
   global void execute(Database.BatchableContext BC,List<sObject> scope)
   {
        System.Debug('#######executeCalled');
        System.Debug('#######callsamplesList'+scope);
        Eisai_TaskHelper_Cls obj = new Eisai_TaskHelper_Cls (); 
        //obj.SendmailtoHCP_forBatch(scope);
        obj.sendHcpCntatdBatchMail(scope);
   }//end of execute
   global void finish(Database.BatchableContext BC)
   {

   }

}//end of batch class


Another Apex Class: 

global Class Eisai_HCPMail_Schedule_Cls implements Schedulable {
public String query; 
global void execute(SchedulableContext sc)
{
 System.Debug('@@@@@@SchedulerCalled');


      query='Select '+
            'Assigned_To_esi__c,Task_Owner_Profile__c,Assign_To_Med_Comm_esi__c,Assign_User_Email__c,HCP_Contacted_Date_esi__c,  '+
            'HCP_Contacted_esi__c,HCP_Contacted_text__c,OwnerId,No_of_Reminder_eMails_esi__c,whoId,Number_of_Days_to_Contact_esi__c '+ 
            'from Task '+
            'WHERE HCP_Contacted_esi__c =false '+
            'and Is_HCP_enable_esi__c =true '+
            'and Number_of_Days_to_Contact_value__c > 3 '+
            'and No_of_Reminder_eMails_esi__c < 3 '+
      //      'and OwnerId=\'005A0000002KfY1\''+
          ' and Status !=\'Completed\''+
            ' and Request_Type_esi__c =\'MSL Request\'';

Id batchInstanceId = Database.executeBatch(new Eisai_HCPMail_Batchable_Cls(query),5);  

}
}
I'm trying to schedule a couple of Apex Classes to run weekly.

When I attempt this in our "Sandbox" environment I can go to Develop > Apex Classes > Schedule Apex and the available Apex Classes appear but when I try this in the "Live" environment no Apex Classes are available to schedule (they appear in the Apex Classes section but do not appear in the Schedule Apex section)

The message returned says
No records found due to one of the following:
  • There are no records of this type
  • You don't have permission to see any of the records

I have admin rights and I've tried to schedule them using our other admin users login details but with no luck.

Is this a problem with my access rights (and how do get the necessary access rights) or is there something obvious that I'm missing?

Many thanks

Alec