• Cris9931
  • NEWBIE
  • 149 Points
  • Member since 2019
  • Admin

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 45
    Questions
  • 55
    Replies

Hello,  I have the following text:   

User-added image 

I have the 'WOT Order' in this string. What I want to achieve is the following:  I created 2 text fields:    
 
1. The Task has been already completed
2. User not allowed to complete the task in future date
 
Now, I want to store in these fields the WOT Order corresponding to each error message.  
 
First Example: In the first row we have WOT Order :0010 following by both error messages; (1)Task has been already completed.  (2)If the user is authorized,then he can set completed date as future date.  
 
I want to populate in this case:  
 
1. The Task has been already completed: 0010
2. User not allowed to complete the task in future: 0010.  
 
Second Example: For the next record I have WOT Order :0020 but its only for this error message:  If the user is authorized,then he can set completed date as future date.  
 
I want to populate in this case:  
 
1. The Task has been already completed: 
2.  User not allowed to complete the task in future date: 0020   
 
And so on... How can I accomplish this? Do I need to use regex?

Hi, how can I accomplish this with a visualforce page: I have the following:

one public group called A to see pickist values 1,2,3
one public group called B to see picklist values 3,2,1
one public group called C to see picklist values 1,3,2

Now in visualforce page I want to dynamically display it if the current user is for example in public group B to display only the values 3,2,1.

 

Hi, can anyone give me some feedback at how can I cover these lines of code in my test class?

for(SVMXC__Service_Order_Line__c wd : workDetails)  
            {  
                String key = '' + wd.SVMXC__Group_Member__r.SVMXC__Salesforce_User__c + wd.SVMXC__Start_Date_and_Time__c.date();  
                SVMXC__Timesheet_Day_Entry__c tde = dayEntries.get(key);  
                if(tde != null)   
                {   
                   SVMXC__Timesheet_Entry__c timeEntry = new SVMXC__Timesheet_Entry__c(); 
                   timeEntry.SVMXC__Timesheet__c = tde.SVMXC__Timesheet__c;   
                   timeEntry.SVMXC__Timesheet_Day__c = tde.Id;   
                   timeEntry.SVMXC__Work_Detail__c = wd.Id;   
                   timeEntry.SVMXC__Start_Time__c = wd.SVMXC__Start_Date_and_Time__c;   
                   timeEntry.SVMXC__End_Time__c = wd.SVMXC__End_Date_and_Time__c;   
                   timeEntry.SVMXC__Comments__c = wd.SIG_Activity_type__c;   
                   timeEntry.SIG_Is_Billable__c  = true;         
                   timeEntry.SVMXC__Account__c  = wd.SIG_Ship_To__c;         
                   timeEntry.SVMXC__Duration__c = wd.SVMX_Duration__c / 60;   
                   timeEntries.add(timeEntry);  
                }
From line 2 above the code is red and is not covered and I can't understand how to cover it.

Hi, I'm stuck with this test class, I can't progress to 75% at least. I'm trying to make a code coverage for this part of the code:

User-added imageCan anyone give me some hints on how can I cover this?

 

My test class:

@isTest
public class scheduledBatchTimeEntryForWorkDetail_UT
{

    static testMethod void testTimeEntryCreation()
    {
        Profile fsmProf = [SELECT Id FROM Profile WHERE Name='SIG-FSM-Field Service Engineer' limit 1];
        User fsmUser = new User(Alias = 'testfsm1', Email='testfsm1@test.com', 
                                EmailEncodingKey='UTF-8', LastName='TestFSM1', LanguageLocaleKey='en_US', 
                                LocaleSidKey='en_US', ProfileId = fsmProf.Id, 
                                TimeZoneSidKey='America/Los_Angeles', UserName='testfsm1@test.com',
                                SIG_Ticket_Recipient__c = 'AM-N - FSE', isActive=true, SIG_Is_User_Authorized__c = true);
        insert fsmUser;
        
        SVMXC__Service_Group__c serviceTeam = new SVMXC__Service_Group__c();
        serviceTeam.SVMXC__Active__c = True;
        serviceTeam.Name = 'Test Service Group';
        insert serviceTeam;
        
        SVMXC__Service_Group_Members__c tech = new SVMXC__Service_Group_Members__c();
        tech.Name='Test Tech';
        tech.SVMXC__Service_Group__c = serviceTeam.id;
        tech.SVMXC__Salesforce_User__c = fsmUser.Id;
        insert tech;
        
        //insert work order
        SVMXC__Service_Order__c  workOrder = new SVMXC__Service_Order__c ();
        workOrder.SVMXC__Order_Status__c  = 'Open';
        workOrder.SVMXC__Sub_Status__c = 'Unresolved';
        workOrder.SVMXC__Priority__c = 'Low';
        workOrder.SVMXC__Order_Type__c = 'Reactive';
        workOrder.SVMXC__Group_Member__c  = tech.Id;
        insert workOrder; 
        

        
        //insert work detail
        SVMXC__Service_Order_Line__c woDetail = new SVMXC__Service_Order_Line__c();
        Id workDetailRecordTypeId = Schema.SObjectType.SVMXC__Service_Order_Line__c.getRecordTypeInfosByName().get('Usage/Consumption').getRecordTypeId();
        woDetail.RecordTypeId = workDetailRecordTypeId;
        woDetail.SVMXC__Service_Order__c = workOrder.Id;
        woDetail.SVMXC__Line_Type__c ='Labor';
        woDetail.SVMXC__Line_Status__c = 'Processed';
        woDetail.SVMXC__Start_Date_and_Time__c = system.today();
        woDetail.SVMXC__End_Date_and_Time__c = system.today()+1;
        woDetail.SVMXC__Group_Member__c =  tech.Id;
        insert woDetail; 
        
        Id workDetailTechnicianId = woDetail.SVMXC__Group_Member__c;

        //insert timesheet
        SVMXC__Timesheet__c weekelyTimeEntries = new SVMXC__Timesheet__c();
        weekelyTimeEntries.SIG_Timesheet_Technician__c =   workDetailTechnicianId;
        weekelyTimeEntries.SVMXC__Start_Date__c = System.Today();
        weekelyTimeEntries.SVMXC__User__c = UserInfo.getUserId();
        insert weekelyTimeEntries;
        
        
        //insert dailyEntries
        SVMXC__Timesheet_Day_Entry__c dayEntries = new SVMXC__Timesheet_Day_Entry__c();
        dayEntries.SVMXC__Timesheet__c = weekelyTimeEntries.Id;
        dayEntries.SVMXC__Timsheet_Day__c = System.Today();
        insert dayEntries;

        //insert time entries
        SVMXC__Timesheet_Entry__c timeEntries = new SVMXC__Timesheet_Entry__c();
        timeEntries.SVMXC__Timesheet__c = weekelyTimeEntries.Id;
        timeEntries.SVMXC__Timesheet_Day__c = dayEntries.Id;
        timeEntries.SVMXC__Work_Detail__c = woDetail.Id;
        timeEntries.SVMXC__Start_Time__c = woDetail.SVMXC__Start_Date_and_Time__c;
        timeEntries.SVMXC__End_Time__c = woDetail.SVMXC__End_Date_and_Time__c;
        timeEntries.SIG_Is_Billable__c  = true;  
        insert timeEntries;

        
        // This test runs a scheduled job at midnight Sept. 3rd. 2022
        String CRON_EXP = '0 0 0 3 9 ? 2022';
        // Schedule the test job
        String jobId = System.schedule('scheduledBatchTimeEntryForWorkDetail_UT', CRON_EXP, new scheduledBatchTimeEntryForWorkDetail());
        // Get the information from the CronTrigger API object 
         CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId]; 
        // Verify the expressions are the same System.assertEquals(CRON_EXP, ct.CronExpression); 
        // Verify the job has not run 
        System.assertEquals(0, ct.TimesTriggered); 
        // Verify the next time the job will run 
         System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime));   
             
     
    }
}


the schedule apex class:

global class scheduledBatchTimeEntryForWorkDetail implements Schedulable 
    {
        global void execute(SchedulableContext sc) 
        {
            List<SVMXC__Service_Order_Line__c> workDetails = new List<SVMXC__Service_Order_Line__c>(); 
            Set<Id> techIds = new Set<Id>(); 
                 // techId = '00001' which is for Diego Technician - Salesforce ID
            
            //run the script for all work details that are in the range of 6 months
            DateTime refDate = DateTime.Now();
            DateTime EndDateInterval =  refDate.AddDays(-180);
     
            for(SVMXC__Service_Order_Line__c wd : [SELECT Id, SVMXC__Group_Member__r.SVMXC__Salesforce_User__c,SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c,SVMX_Duration__c, SVMXC__Line_Type__c,                                        SIG_Activity_type__c, SIG_Ship_To__c, 
                                          (SELECT Id FROM SVMXC__Time_Entrys__r)  FROM SVMXC__Service_Order_Line__c            
                                           WHERE (SVMXC__Line_Type__c='Labor' OR SVMXC__Line_Type__c='Travel')           
                                                 AND SVMXC__Group_Member__c!=null AND SVMXC__Line_Status__c = 'Processed'           
                                                 AND (SVMXC__Start_Date_and_Time__c <= :refDate AND SVMXC__Start_Date_and_Time__c >= :EndDateInterval)]) 
            {     
                if(wd.SVMXC__Time_Entrys__r.size() == 0) 
                {   
                    workDetails.add(wd);   
                    techIds.add(wd.SVMXC__Group_Member__r.SVMXC__Salesforce_User__c);  
                } 
            } 
    System.debug('### workDetails : ' + workDetails.size());
    
            Map<String, SVMXC__Timesheet_Day_Entry__c> dayEntries = new Map<String, SVMXC__Timesheet_Day_Entry__c>(); 
     
            for(SVMXC__Timesheet_Day_Entry__c tde : [SELECT Id, SVMXC__Timesheet__c, SVMXC__Timesheet__r.SVMXC__User__c, SVMXC__Timsheet_Day__c FROM SVMXC__Timesheet_Day_Entry__c WHERE SVMXC__Timesheet__r.SVMXC__User__c IN :techIds]) 
            {  
                String key = '' + tde.SVMXC__Timesheet__r.SVMXC__User__c + tde.SVMXC__Timsheet_Day__c;
                dayEntries.put(key, tde); 
            } 

    System.debug('### dayEntries : ' + dayEntries.size()); 
     
     
            List<SVMXC__Timesheet_Entry__c> timeEntries = new List<SVMXC__Timesheet_Entry__c>(); 
    
            for(SVMXC__Service_Order_Line__c wd : workDetails)  
            {  
                String key = '' + wd.SVMXC__Group_Member__r.SVMXC__Salesforce_User__c + wd.SVMXC__Start_Date_and_Time__c.date();  
                SVMXC__Timesheet_Day_Entry__c tde = dayEntries.get(key);  
                if(tde != null)   
                {   
                   SVMXC__Timesheet_Entry__c timeEntry = new SVMXC__Timesheet_Entry__c(); 
                   timeEntry.SVMXC__Timesheet__c = tde.SVMXC__Timesheet__c;   
                   timeEntry.SVMXC__Timesheet_Day__c = tde.Id;   
                   timeEntry.SVMXC__Work_Detail__c = wd.Id;   
                   timeEntry.SVMXC__Start_Time__c = wd.SVMXC__Start_Date_and_Time__c;   
                   timeEntry.SVMXC__End_Time__c = wd.SVMXC__End_Date_and_Time__c;   
                   timeEntry.SVMXC__Comments__c = wd.SIG_Activity_type__c;   
                   timeEntry.SIG_Is_Billable__c  = true;         
                   timeEntry.SVMXC__Account__c  = wd.SIG_Ship_To__c;         
                   timeEntry.SVMXC__Duration__c = wd.SVMX_Duration__c / 60;   
                   timeEntries.add(timeEntry);  
                } 
            } 
     
    System.debug('### timeEntries : ' + timeEntries.size()); 
     
            if(timeEntries.size() > 0)  
                insert timeEntries;
        }
    }

​​​​​​​
Hello, can anyone give me a help with a batch class? I have this code which is working fine in my developer console if I run it in anonymous ..
 
List<SVMXC__Service_Order_Line__c> workDetails = new List<SVMXC__Service_Order_Line__c>(); 
Set<Id> techIds = new Set<Id>(); 
//Last Run Oct 8 
DateTime refDate = DateTime.newInstance(2019, 10, 01);
DateTime EndDateInterval =  refDate.AddDays(7);
 
for(SVMXC__Service_Order_Line__c wd : [SELECT Id, SVMXC__Group_Member__r.SVMXC__Salesforce_User__c,SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c,SVMX_Duration__c, SVMXC__Line_Type__c,                                        SIG_Activity_type__c, SIG_Ship_To__c, 
                                      (SELECT Id FROM SVMXC__Time_Entrys__r)  FROM SVMXC__Service_Order_Line__c            
		                               WHERE (SVMXC__Line_Type__c='Labor' OR SVMXC__Line_Type__c='Travel')           
									         AND SVMXC__Group_Member__c!=null AND SVMXC__Line_Status__c = 'Processed'           
											 AND (SVMXC__Start_Date_and_Time__c >= :refDate AND SVMXC__Start_Date_and_Time__c <= :EndDateInterval)]) 
   {     
      if(wd.SVMXC__Time_Entrys__r.size() == 0) 
	  {   
	     workDetails.add(wd);   
		 techIds.add(wd.SVMXC__Group_Member__r.SVMXC__Salesforce_User__c);  
	  } 
   } 
   
   
System.debug('### workDetails : ' + workDetails.size());

 
 
Map<String, SVMXC__Timesheet_Day_Entry__c> dayEntries = new Map<String, SVMXC__Timesheet_Day_Entry__c>(); 
 
for(SVMXC__Timesheet_Day_Entry__c tde : [SELECT Id, SVMXC__Timesheet__c, SVMXC__Timesheet__r.SVMXC__User__c, SVMXC__Timsheet_Day__c FROM SVMXC__Timesheet_Day_Entry__c WHERE SVMXC__Timesheet__r.SVMXC__User__c IN :techIds]) 
   {  
       String key = '' + tde.SVMXC__Timesheet__r.SVMXC__User__c + tde.SVMXC__Timsheet_Day__c;  
	   dayEntries.put(key, tde); 
   } 
   
System.debug('### dayEntries : ' + dayEntries.size()); 
 
 
List<SVMXC__Timesheet_Entry__c> timeEntries = new List<SVMXC__Timesheet_Entry__c>(); 


for(SVMXC__Service_Order_Line__c wd : workDetails)  
   {  
       String key = '' + wd.SVMXC__Group_Member__r.SVMXC__Salesforce_User__c + wd.SVMXC__Start_Date_and_Time__c.date();  
	   SVMXC__Timesheet_Day_Entry__c tde = dayEntries.get(key);  
	   
	   if(tde != null)   
	       {   SVMXC__Timesheet_Entry__c timeEntry = new SVMXC__Timesheet_Entry__c(); 
               timeEntry.SVMXC__Timesheet__c = tde.SVMXC__Timesheet__c;   timeEntry.SVMXC__Timesheet_Day__c = tde.Id;   
			   timeEntry.SVMXC__Work_Detail__c = wd.Id;   
			   timeEntry.SVMXC__Start_Time__c = wd.SVMXC__Start_Date_and_Time__c;   
			   timeEntry.SVMXC__End_Time__c = wd.SVMXC__End_Date_and_Time__c;   
			   timeEntry.SVMXC__Comments__c = wd.SIG_Activity_type__c;   
			   timeEntry.SIG_Is_Billable__c  = true;         
			   timeEntry.SVMXC__Account__c  = wd.SIG_Ship_To__c;         
			   timeEntry.SVMXC__Duration__c = wd.SVMX_Duration__c / 60;   
			   timeEntries.add(timeEntry);  
		   } 
   } 
 
System.debug('### timeEntries : ' + timeEntries.size()); 
 
if(timeEntries.size() > 0)  
insert timeEntries;

 

Hi, on this line I have this error:

SVMXC__Timesheet_Entry__c relatedTimeEntry = [Select ID, SVMXC__Work_Detail__c from SVMXC__Timesheet_Entry__c where SVMXC__Work_Detail__c IN :  workDetailIds limit 1];
 
trigger updateTimeEntriesHolidays on SVMXC__Service_Order_Line__c (after update) {

        //custom setting approach------------******* START
        Map<String, Holidays__mdt> holidays = Holidays__mdt.getAll();
        Map<Date, Holidays__mdt> holidaysMap = new Map<Date,Holidays__mdt>();

        
        Set<Id> workDetailIds = new Set<Id>();
        
        for(SVMXC__Service_Order_Line__c newLines : Trigger.New)
        {
            
            if (newLines.SVMX_PS_Customer_Start_Date__c != Trigger.oldMap.get(newLines.Id).SVMX_PS_Customer_Start_Date__c) {
                workDetailIds.add(newLines.Id);
            } 
        }
        
        
         for(Holidays__mdt ho: holidays.values())
         {
             holidaysMap.put(ho.Holiday_Date__c, ho);
         }
         

       SVMXC__Timesheet_Entry__c relatedTimeEntry = [Select ID, SVMXC__Work_Detail__c from SVMXC__Timesheet_Entry__c where SVMXC__Work_Detail__c IN :  workDetailIds limit 1];

        
                        
        List<SVMXC__Timesheet_Entry__c> TimeEntryToUpdate = new List<SVMXC__Timesheet_Entry__c>();
        
        
         for(SVMXC__Service_Order_Line__c wl: Trigger.New)
         {
              Date workDetailStartDate = wl.SVMX_PS_Customer_Start_Date__c;
             
              if(holidaysMap.containsKey(workDetailStartDate ))
              {
                  Date getDateHoliday =  holidaysMap.get(workDetailStartDate).Holiday_Date__c;
                  
                  if(workDetailStartDate == getDateHoliday)
                  {
                      SVMXC__Timesheet_Entry__c newTimeEntry = new SVMXC__Timesheet_Entry__c();
                      newTimeEntry.Id = relatedTimeEntry.Id;
                      newTimeEntry.isHoliday__c = TRUE;
                      TimeEntryToUpdate.add(newTimeEntry);
                  }
              }
              else
              {
                 SVMXC__Timesheet_Entry__c newTimeEntry = new SVMXC__Timesheet_Entry__c();
                      newTimeEntry.Id = relatedTimeEntry.Id;
                      newTimeEntry.isHoliday__c = False;
                      TimeEntryToUpdate.add(newTimeEntry);
              }
            
         }
         
         update TimeEntryToUpdate ;
         System.debug('TimeEntryToUpdate'+ TimeEntryToUpdate);
}

How can I get rid of the error? As far As I saw the reason this error comes is because I have no results for that query...no?
Hi, I want to create a trigger for the following scenario... I have 4 fields:
0. Reported Start Date(date datatype)
1. Reported Start Time(time datatype)
3. Reported End Date(Date datatype)
4. Reported End Time(time datatype)

Only the following interval of time is relevant, from 22:00(10PM) - 00:00(12 AM, next day). This interval is important because I want to display the value from formula field based on this interval of time.

Example: I have from 10:00 PM - 01:00 AM,  display show 120 minutes, because we only count  minutes in this interval of time.
Example 2: I have from 08:00 PM - 10:00 PM, display nothing(blank), because is not included in this interval of time.
Example 3: I have from 11:00 PM - 00:00 AM, display 60 minutes.

The minutes I want to be displayed in a field called Calculated_Time__c... any ideas how can I do this?
Hi, I want to create a formula field for the following scenario... I have 4 fields:
0. Reported Start Date(date datatype)
1. Reported Start Time(time datatype)
3. Reported End Date(Date datatype)
4. Reported End Time(time datatype)

Only the following interval of time is relevant, from 22:00(10PM) - 00:00(12 AM, next day). This interval is important because I want to display the value from formula field based on this interval of time.

Example: I have from 10:00 PM - 01:00 AM,  display show 120 minutes, because we only count  minutes in this interval of time.
Example 2: I have from 08:00 PM - 10:00 PM, display nothing(blank), because is not included in this interval of time.
Example 3: I have from 11:00 PM - 00:00 AM, display 60 minutes.

And so on.... Is it possible?

Hello, I need some help to write the logic to count dupplication on 2 objects. I will show the relationships between the objects:

User-added image

On Installed Product object I have the field: Duplicate Work Order TaskOn this field I need to update with the number if I have a duplicated Work Order Task. Now, what a duplicated Work Order Task means? It means if a Work Order Task has the same Task Template and Work Order it means it is duplicated, like so:

User-added image

How can I do this? I managed to write the code(and it works) when I have a duplicated Task Template:

 

public static void updateTaskAvailabilitiesDuplication(Map<Id, SVMX_PS_Work_Order_Task__c> newMap) 
     {

        Map<Id, List<id>> duplicateTaskTemplateCountMap = new Map<Id, List<id>>();
        Map<Id, List<id>> duplicateWorkOrderCountMap = new Map<Id, List<id>>();
        
        List<SVMXC__Installed_Product__c> instProductToUpdate = new List<SVMXC__Installed_Product__c>();
        Set<Id> IpIds = new Set<Id>();

        if(newMap != null && !newMap.isEmpty()){

            for(SVMX_PS_Work_Order_Task__c woTask : newMap.values())
            {
                IpIds.add(woTask.SVMX_PS_Installed_Product__c);
                
            }
 
            for(SVMX_PS_Work_Order_Task__c woTasks: [Select SVMX_PS_SIG_Work_Order__c, SVMX_PS_Task_Template_Id__c, SVMX_PS_Installed_Product__c from SVMX_PS_Work_Order_Task__c where SVMX_PS_Installed_Product__c =: IPIds])
            {
                if(duplicateTaskTemplateCountMap.get(woTasks.SVMX_PS_Installed_Product__c) != null){
                    duplicateTaskTemplateCountMap.get(woTasks.SVMX_PS_Installed_Product__c).add(woTasks.SVMX_PS_Task_Template_Id__c);
                } else {
                    List<String> listString = new List<String>();
                    listString.add(woTasks.SVMX_PS_Task_Template_Id__c);
                    duplicateTaskTemplateCountMap.put(woTasks.SVMX_PS_Installed_Product__c, listString);

                }
            }
            if(duplicateTaskTemplateCountMap != null){
                 system.debug('::::duplicateTaskTemplateCountMap:::'+JSON.serialize(duplicateTaskTemplateCountMap));
            }
           
            for(Id ipId : duplicateTaskTemplateCountMap.keySet()) {         
                    Set<Id> templateIdSet = new Set<Id>(duplicateTaskTemplateCountMap.get(ipId));
                    
                    List<Id> templateList = new List<Id>();
                    for(Id templateId : templateIdSet) {
                        templateList = duplicateTaskTemplateCountMap.get(ipId);
                        templateList.remove(templateList.indexOf(templateId));
                    }
                    templateIdSet = new Set<Id>(templateList);
                    system.debug('::::templateList.size():::'+templateIdSet.size());
                    
                    SVMXC__Installed_Product__c instProd = new SVMXC__Installed_Product__c();
                    instProd.Id = ipId;
                    instProd.Duplications_Work_Order_Tasks__c = templateIdSet.size();
                    instProductToUpdate.add(instProd);   
            }

            if(instProductToUpdate.size() > 0){
                update instProductToUpdate;
            }
            
        }
 

But I'm stuck here..

Hi, how can I cover these remaining lines for this class? I'm struggling to understand why it is not covering all.. This is my class and coverage, I have 66% until now.

User-added image
This is my method from the test class which covers 66%.

 

static testMethod void linkTest() {

        
       	SVMXC__Service_Request__c sr = new SVMXC__Service_Request__c();
        sr.SVMXC__Status__c = 'Closed';
        sr.SVMXC__Priority__c = 'Medium';
        sr.Number_of_Open_Admin_Tasks__c = 2;
        sr.SVMXC__Type__c = 'Complaint CCM';
        insert sr;
        
    	List<SVMXC__Service_Request__c> listSr = [Select Id, SVMXC__Status__c, Name from SVMXC__Service_Request__c where Id=: sr.Id ];
    	
    	ApexPages.StandardSetController setCtr = new ApexPages.StandardSetController(listSr);
    	setCtr.setSelected(new SVMXC__Service_Request__c[]{sr});
        MassUpdateSimpleControllerServiceRequest controller = new MassUpdateSimpleControllerServiceRequest(setCtr);
		
		// verify following exceptions will not cause exception
		System.assert(controller.step1()!=null);   
        controller.lexstep1();
		System.assert(controller.step2()!=null);
        controller.lexstep2();
        controller.getFieldTypeOptions();
		System.assert(controller.step3()!=null);
        controller.lexstep3();
		System.assert(controller.step4()!=null);
        controller.lexstep4();
		System.assert(controller.step5()!=null);
        controller.lexstep5();
		//System.assert(controller.cancel()!=null);
		
	
    }

Hi, I have this simple trigger and I'm not sure which line is causing the problem...:

trigger SIG_Trigger_IT_WO on SVMXC__Service_Order__c (before insert, before update) {


    Set<Id> srId = new Set<Id>();
    List<SVMXC__Service_Request__c> srToUpdate= new List<SVMXC__Service_Request__c>();
    
        for(SVMXC__Service_Order__c wos : Trigger.New){
            srId.add(wos.SVMXC__SM_Service_Request__c);
        }
        
        List<SVMXC__Service_Request__c> sr= [select id, Number_of_Open_Work_Orders__c from SVMXC__Service_Request__c where Id in :srId ];
        List<SVMXC__Service_Order__c > wos= [select id, SVMXC__Order_Status__c from SVMXC__Service_Order__c where (SVMXC__Order_Status__c != 'Closed' AND SVMXC__Order_Status__c != 'Cancelled') AND SVMXC__SM_Service_Request__c in :srId  ];
        for(SVMXC__Service_Request__c s : sr){
            s.Number_of_Open_Work_Orders__c = wos.size();
           srToUpdate.add(s);
        }
        update srToUpdate;


}

Can someone help me?

Hello, I created the following custom setting:
User-added imageI have a list of translated words for German and Spanish and they are strictly dependent on what the English word will be entered in the record. On my object I have 3 fields, for English, German and Spanish.
How to make a logic in a trigger that whenever the field(which is in English) has some values than automatically the German field and Spanish field should populate with the corresponding value.
Example, let's say I change a record and I put 'Car' in the field which is used for English language.

 

User-added imageLike so... After saving it I want to populate the Task Type(DE) with 'Wagen' and Task Type(ES) with 'Automombile' because that's how I defined in the custom setting.
I tried to write the logic by myself but I failed. 

 

public static void onBeforeUpdate(Map<Id, SVMX_PS_PM_Task_Template__c> newMap)
    {
        Map<string,Translations__c > translation = Translations__c.getAll();
        
        for(SVMX_PS_PM_Task_Template__c newTemplate : newMap.values()){
            String storeValue = newTemplate.SVMX_PS_Task_Type__c;
            
         
              try{
                String germanTranslation = translation.get(storeValue).German__c;
                String englishTranslation = translation.get(storeValue).English__c;
                System.debug('english' + englishTranslation);
                String spanishTranslation = translation.get(storeValue).Spanish__c;
                newTemplate.Task_Type_DE__c = germanTranslation;
                newTemplate.Task_Type_ES__c = spanishTranslation;
              }
               catch(exception e) {
               newTemplate.Task_Type_DE__c = '';
               newTemplate.Task_Type_ES__c = '';
              }
        }
       
    }

Thanks

Hello, we generate in Salesforce documents and I don't know how to configure to be like this: 

User-added image

But currently in our org is like this:

 

User-added image

Which doesnt look nice. Notice how the table is not ending on the first page and on the second page it doesnt even looks like a table because the horizontal line is missing...

How can I solve this?

Hi, I have an error in my trigger and I'm not sure why I get it... It is like this: BeforeUpdate cause by: System.DMLException; Upsert field. FIeld Exeception on row 0; first error; CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Execution of AfterUpdate cause by: System.NullPointerException: Argument cannot be null();

 

This is the snippet code where the error is happening....

List<Id> woIds = new List<Id>();
        List<DateTime> listDateTimesValues = new List<DateTime>();
        List<DateTime> listDateTimesValues2 = new List<DateTime>();
        
        for(SVMXC__Service_Order_Line__c storeWo : newMap.values()){
              woIds.add(storeWo.SVMXC__Service_Order__c);
        }
        //store all the work details related to the Work Order
        List<SVMXC__Service_Order_Line__c> relatedWorkDetails = [SELECT ID, SIG_Start_Date_Time_Device__c , SIG_End_Date_Time_Device__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c =: woIds]; 
        
        //fetch the current Work Order
        List<SVMXC__Service_Order__c> currentWorkOrder = [SELECT ID, Start_of_Work_c__c, End_of_Work__c from SVMXC__Service_Order__c where ID =: woIds];
        
        if(relatedWorkDetails.size() >0 ){
        for(SVMXC__Service_Order_Line__c workDetail : relatedWorkDetails ){
          
          DateTime dt = DateTime.valueOfGMT(workDetail.SIG_Start_Date_Time_Device__c);
          listDateTimesValues.add(dt);       
          listDateTimesValues.sort();
          
          DateTime dt2 = DateTime.valueOfGMT(workDetail.SIG_End_Date_Time_Device__c);
          listDateTimesValues2.add(dt2); 
          listDateTimesValues2.sort();
        }}
        
        //check how many items are in the list
        Integer nrOfItemsInTheList = listDateTimesValues.size() -1;
        Integer nrOfItemsInTheList2 = listDateTimesValues2.size() -1;
        
          DateTime minDateTime = listDateTimesValues[0];
          DateTime maxDateTime = listDateTimesValues2[nrOfItemsInTheList];
          System.debug('minDateTime '+minDateTime );
          System.debug('maxDateTime '+maxDateTime );
         
         //convert the minDateTime and maxDateTime in a text to avoid time Conversion
          String stringMinDateTime = String.valueOfGmt(minDateTime);
          String stringMaxDateTime = String.valueOfGmt(maxDateTime);
          
          System.debug('stringMinDateTime '+ stringMinDateTime );
          System.debug('stringMaxDateTime '+ stringMaxDateTime );
         
          
          List<SVMXC__Service_Order__c> woToUpdate = new List<SVMXC__Service_Order__c>();
          
          for(SVMXC__Service_Order__c workOrder : currentWorkOrder) {
              workOrder.Start_of_Work_c__c= stringMinDateTime;
              workOrder.End_of_Work__c = stringMaxDateTime;
              woToUpdate.add(workOrder);
          }
       
          if(!woToUpdate.isEmpty()){
            update woToUpdate;
          }

What I'm doing wrong here?
I created a LWC chart and for whatever reason I have this error.. but only for some records and I don't know why.
 
import { api, LightningElement, track } from 'lwc';
import chartJS from '@salesforce/resourceUrl/chart';
import { loadScript } from 'lightning/platformResourceLoader';
import getChartDetail from '@salesforce/apex/RenderChart.getChartDetail';
import { ShowToastEvent } from "lightning/platformShowToastEvent";

export default class myRadarChart extends LightningElement {
    @api recordId;
    @track chartData = [];
    @track chartLabel = [];
    getRandomColor() {
      var letters = '0123456789ABCDEF';
      var color = '#';
      for (var i = 0; i < 6; i++) {
        color += letters[Math.floor(Math.random() * 16)];
      }
      return color;
    }
    connectedCallback(){
        loadScript(this, chartJS + "/Chart.min.js")
      .then(() => {
      
      })
    .catch((error) => {
      console.log("Error:", error);
    });
    getChartDetail({
      oppId : this.recordId
    }).then(result => {
      var tempresult = JSON.parse(JSON.stringify(result));
      this.chartLabel = ["Power","Collaborate","CRTA","Pain","Value","Vision"];
      this.chartData = [];
      for(let temp of tempresult){
        let color = this.getRandomColor();
        let tempdata = [];
        tempdata.push(temp.Power_no_concat__c);
        tempdata.push(temp.Collaborate_no_concat__c);
        tempdata.push(temp.Compelling_Reason_to_Act_CRTA_no_concat__c);
        tempdata.push(temp.Pain_no_concat__c);
        tempdata.push(temp.Value_no_concat__c);
        tempdata.push(temp.Vision_no_concat__c);
        let chartMap = {
          label: temp.Name,
          borderColor: color,
          fill: false,
          pointHoverBackgroundColor: color,
          backgroundColor: "rgba(255,255,255, 0)",
          data: tempdata
        }
        this.chartData.push(chartMap);
      }
      this.callRadarChart();
    }).catch(error => {
      console.error('Error in RenderChart.getChartDetail' + error);
      this.dispatchEvent(new ShowToastEvent({
          title: "Error",
          message: error,
          variant: "error",
          mode: "dismissable"
        }));
      });
    }
    callRadarChart(){
      let config = {
        type: 'radar',
        data: {
          labels: this.chartLabel,
          datasets: this.chartData
        },
        options:{
          legend: {
            display: true,
            position: 'right',
            align: 'center',
            labels: {
              usePointStyle: true,
            }
          }
        }
      };
      this.insertToDOM("div.radarChart",config);
    }
    
    
    insertToDOM(divclass,config) {
      const canvas = document.createElement("canvas");
      const chartNode = this.template.querySelector(divclass);
      chartNode.innerHTML = "";
      chartNode.appendChild(canvas);
      const ctx = canvas.getContext("2d");
      this.chart = new window.Chart(ctx, config);

    }
}


apex class:

public with sharing class RenderChart {
    @AuraEnabled(cacheable=true)
    public static List<Sales_Check__c> getChartDetail(String oppId) {
        Map<String,Decimal> mapnumberfields = new Map<String,Decimal>();
        List<Sales_Check__c> salesCheckList = [SELECT Id, Name,Collaborate_no_concat__c, Compelling_Reason_to_Act_CRTA_no_concat__c, Pain_no_concat__c, Value_no_concat__c, Vision_no_concat__c, Power_no_concat__c FROM Sales_Check__c Where Opportunity__c =:oppId];
        return salesCheckList;   
    }
}

 

This is the error i'm getting it:

User-added image

Why i'm getting this error?

I have a DateTime text field.

User-added image

I created a short trigger to convert this DateTime text in actual DateTime.
 
List<Id> listWoId = new List<Id>();
        
        for(SVMXC__Service_Order__c loopwo : Trigger.new){
              listWoId.add(loopwo.Id);
        }
        
        List<SVMXC__Service_Order_Line__c> currentWL = [SELECT ID, Name, SIG_Start_Date_Time_Device__c , SIG_End_Date_Time_Device__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c =: listWoId]; 
        
        for(SVMXC__Service_Order_Line__c workDetail : currentWL ){
        
          
          DateTime dt = DateTime.valueOf(workDetail.SIG_Start_Date_Time_Device__c);
          System.debug('Work Detail Number: ' +workDetail.Name + '   #####     ' + 'DateTime :' + dt);

        }


If I take a look on my work details I see that Start Date/Time - Device is not the same with what I received in my system debug...
 
This is how it looks without any time conversion, its basically a text of DateTime.

User-added imageBut when I system debug this I get converted value:

User-added imageHow can I get the original value from the WEB and avoid the time conversion? Please help.. I'm stuck with this.

Hi, I have a master-detail relationship between two custom objects. Work Order(master) - Work Detail(detail).

On Work Detail I have 2 fields which displays Date/Time but in a text field format. Like this:

User-added image

 

How to make a trigger without time conversion to display the maximum and minimum dateTime from the child(work detail)?

I started writing the trigger:

List<Id> listWoId = new List<Id>();
        
        for(SVMXC__Service_Order__c loopwo : Trigger.new){
              listWoId.add(loopwo.Id);
        }
        
        List<SVMXC__Service_Order_Line__c> currentWL = [SELECT ID, Name, SIG_Start_Date_Time_Device__c , SIG_End_Date_Time_Device__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c =: listWoId]; 
        
        for(SVMXC__Service_Order_Line__c workDetail : currentWL ){

          DateTime dt = DateTime.valueOf(workDetail.SIG_Start_Date_Time_Device__c);
          System.debug('dt' + dt);
        }

But this is not working, I tried to change the timezone from my user and everytime I change and System.Debug I see different DateTime because of the timezone conversion...how can I avoid this?
I have the following:
for(SVMXC__SVMX_Event__c svmxEv : Trigger.New)
    {
       
        System.debug('#############' + svmxEv.SVMXC__Technician__r.SVMXC__Service_Group__r.Name);
    }

User-added image


I tried to make a formula field with this: SVMXC__Technician__r.SVMXC__Service_Group__r.Name and it's working... I don't know why in my trigger it's not working...
P.S. my trigger is after update, after insert, before update

Hi, I've wrote a trigger to fetch the old Date/Time from a field and store in a new field.. The problem is that it is converting in Local Time and not in UTC... How can I convert my date in UTC timezone?

trigger StartDateTime on SVMXC__SVMX_Event__c (before update) {
 
 for(SVMXC__SVMX_Event__c even : Trigger.New){
    if(even.SVMX_PS_Validated__c == FALSE && (Trigger.newMap.get(even.id).SVMXC__StartDateTime__c) != Trigger.oldMap.get(even.id).SVMXC__StartDateTime__c) {
       even .Original_Date_StartDateTime__c = Trigger.oldMap.get(even.id).SVMXC__StartDateTime__c;

    }
 }
 

}

I see two different timezones

User 1 : GMT 3

User-added image

User 2 : GMT 2

User-added image

Hi, can anyone give me some feedback at how can I cover these lines of code in my test class?

for(SVMXC__Service_Order_Line__c wd : workDetails)  
            {  
                String key = '' + wd.SVMXC__Group_Member__r.SVMXC__Salesforce_User__c + wd.SVMXC__Start_Date_and_Time__c.date();  
                SVMXC__Timesheet_Day_Entry__c tde = dayEntries.get(key);  
                if(tde != null)   
                {   
                   SVMXC__Timesheet_Entry__c timeEntry = new SVMXC__Timesheet_Entry__c(); 
                   timeEntry.SVMXC__Timesheet__c = tde.SVMXC__Timesheet__c;   
                   timeEntry.SVMXC__Timesheet_Day__c = tde.Id;   
                   timeEntry.SVMXC__Work_Detail__c = wd.Id;   
                   timeEntry.SVMXC__Start_Time__c = wd.SVMXC__Start_Date_and_Time__c;   
                   timeEntry.SVMXC__End_Time__c = wd.SVMXC__End_Date_and_Time__c;   
                   timeEntry.SVMXC__Comments__c = wd.SIG_Activity_type__c;   
                   timeEntry.SIG_Is_Billable__c  = true;         
                   timeEntry.SVMXC__Account__c  = wd.SIG_Ship_To__c;         
                   timeEntry.SVMXC__Duration__c = wd.SVMX_Duration__c / 60;   
                   timeEntries.add(timeEntry);  
                }
From line 2 above the code is red and is not covered and I can't understand how to cover it.

Hi, on this line I have this error:

SVMXC__Timesheet_Entry__c relatedTimeEntry = [Select ID, SVMXC__Work_Detail__c from SVMXC__Timesheet_Entry__c where SVMXC__Work_Detail__c IN :  workDetailIds limit 1];
 
trigger updateTimeEntriesHolidays on SVMXC__Service_Order_Line__c (after update) {

        //custom setting approach------------******* START
        Map<String, Holidays__mdt> holidays = Holidays__mdt.getAll();
        Map<Date, Holidays__mdt> holidaysMap = new Map<Date,Holidays__mdt>();

        
        Set<Id> workDetailIds = new Set<Id>();
        
        for(SVMXC__Service_Order_Line__c newLines : Trigger.New)
        {
            
            if (newLines.SVMX_PS_Customer_Start_Date__c != Trigger.oldMap.get(newLines.Id).SVMX_PS_Customer_Start_Date__c) {
                workDetailIds.add(newLines.Id);
            } 
        }
        
        
         for(Holidays__mdt ho: holidays.values())
         {
             holidaysMap.put(ho.Holiday_Date__c, ho);
         }
         

       SVMXC__Timesheet_Entry__c relatedTimeEntry = [Select ID, SVMXC__Work_Detail__c from SVMXC__Timesheet_Entry__c where SVMXC__Work_Detail__c IN :  workDetailIds limit 1];

        
                        
        List<SVMXC__Timesheet_Entry__c> TimeEntryToUpdate = new List<SVMXC__Timesheet_Entry__c>();
        
        
         for(SVMXC__Service_Order_Line__c wl: Trigger.New)
         {
              Date workDetailStartDate = wl.SVMX_PS_Customer_Start_Date__c;
             
              if(holidaysMap.containsKey(workDetailStartDate ))
              {
                  Date getDateHoliday =  holidaysMap.get(workDetailStartDate).Holiday_Date__c;
                  
                  if(workDetailStartDate == getDateHoliday)
                  {
                      SVMXC__Timesheet_Entry__c newTimeEntry = new SVMXC__Timesheet_Entry__c();
                      newTimeEntry.Id = relatedTimeEntry.Id;
                      newTimeEntry.isHoliday__c = TRUE;
                      TimeEntryToUpdate.add(newTimeEntry);
                  }
              }
              else
              {
                 SVMXC__Timesheet_Entry__c newTimeEntry = new SVMXC__Timesheet_Entry__c();
                      newTimeEntry.Id = relatedTimeEntry.Id;
                      newTimeEntry.isHoliday__c = False;
                      TimeEntryToUpdate.add(newTimeEntry);
              }
            
         }
         
         update TimeEntryToUpdate ;
         System.debug('TimeEntryToUpdate'+ TimeEntryToUpdate);
}

How can I get rid of the error? As far As I saw the reason this error comes is because I have no results for that query...no?
Hi, I want to create a trigger for the following scenario... I have 4 fields:
0. Reported Start Date(date datatype)
1. Reported Start Time(time datatype)
3. Reported End Date(Date datatype)
4. Reported End Time(time datatype)

Only the following interval of time is relevant, from 22:00(10PM) - 00:00(12 AM, next day). This interval is important because I want to display the value from formula field based on this interval of time.

Example: I have from 10:00 PM - 01:00 AM,  display show 120 minutes, because we only count  minutes in this interval of time.
Example 2: I have from 08:00 PM - 10:00 PM, display nothing(blank), because is not included in this interval of time.
Example 3: I have from 11:00 PM - 00:00 AM, display 60 minutes.

The minutes I want to be displayed in a field called Calculated_Time__c... any ideas how can I do this?
Hi, I want to create a formula field for the following scenario... I have 4 fields:
0. Reported Start Date(date datatype)
1. Reported Start Time(time datatype)
3. Reported End Date(Date datatype)
4. Reported End Time(time datatype)

Only the following interval of time is relevant, from 22:00(10PM) - 00:00(12 AM, next day). This interval is important because I want to display the value from formula field based on this interval of time.

Example: I have from 10:00 PM - 01:00 AM,  display show 120 minutes, because we only count  minutes in this interval of time.
Example 2: I have from 08:00 PM - 10:00 PM, display nothing(blank), because is not included in this interval of time.
Example 3: I have from 11:00 PM - 00:00 AM, display 60 minutes.

And so on.... Is it possible?

Hi, I have this simple trigger and I'm not sure which line is causing the problem...:

trigger SIG_Trigger_IT_WO on SVMXC__Service_Order__c (before insert, before update) {


    Set<Id> srId = new Set<Id>();
    List<SVMXC__Service_Request__c> srToUpdate= new List<SVMXC__Service_Request__c>();
    
        for(SVMXC__Service_Order__c wos : Trigger.New){
            srId.add(wos.SVMXC__SM_Service_Request__c);
        }
        
        List<SVMXC__Service_Request__c> sr= [select id, Number_of_Open_Work_Orders__c from SVMXC__Service_Request__c where Id in :srId ];
        List<SVMXC__Service_Order__c > wos= [select id, SVMXC__Order_Status__c from SVMXC__Service_Order__c where (SVMXC__Order_Status__c != 'Closed' AND SVMXC__Order_Status__c != 'Cancelled') AND SVMXC__SM_Service_Request__c in :srId  ];
        for(SVMXC__Service_Request__c s : sr){
            s.Number_of_Open_Work_Orders__c = wos.size();
           srToUpdate.add(s);
        }
        update srToUpdate;


}

Can someone help me?

Hello, I created the following custom setting:
User-added imageI have a list of translated words for German and Spanish and they are strictly dependent on what the English word will be entered in the record. On my object I have 3 fields, for English, German and Spanish.
How to make a logic in a trigger that whenever the field(which is in English) has some values than automatically the German field and Spanish field should populate with the corresponding value.
Example, let's say I change a record and I put 'Car' in the field which is used for English language.

 

User-added imageLike so... After saving it I want to populate the Task Type(DE) with 'Wagen' and Task Type(ES) with 'Automombile' because that's how I defined in the custom setting.
I tried to write the logic by myself but I failed. 

 

public static void onBeforeUpdate(Map<Id, SVMX_PS_PM_Task_Template__c> newMap)
    {
        Map<string,Translations__c > translation = Translations__c.getAll();
        
        for(SVMX_PS_PM_Task_Template__c newTemplate : newMap.values()){
            String storeValue = newTemplate.SVMX_PS_Task_Type__c;
            
         
              try{
                String germanTranslation = translation.get(storeValue).German__c;
                String englishTranslation = translation.get(storeValue).English__c;
                System.debug('english' + englishTranslation);
                String spanishTranslation = translation.get(storeValue).Spanish__c;
                newTemplate.Task_Type_DE__c = germanTranslation;
                newTemplate.Task_Type_ES__c = spanishTranslation;
              }
               catch(exception e) {
               newTemplate.Task_Type_DE__c = '';
               newTemplate.Task_Type_ES__c = '';
              }
        }
       
    }

Thanks

Hello, we generate in Salesforce documents and I don't know how to configure to be like this: 

User-added image

But currently in our org is like this:

 

User-added image

Which doesnt look nice. Notice how the table is not ending on the first page and on the second page it doesnt even looks like a table because the horizontal line is missing...

How can I solve this?

I have a DateTime text field.

User-added image

I created a short trigger to convert this DateTime text in actual DateTime.
 
List<Id> listWoId = new List<Id>();
        
        for(SVMXC__Service_Order__c loopwo : Trigger.new){
              listWoId.add(loopwo.Id);
        }
        
        List<SVMXC__Service_Order_Line__c> currentWL = [SELECT ID, Name, SIG_Start_Date_Time_Device__c , SIG_End_Date_Time_Device__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c =: listWoId]; 
        
        for(SVMXC__Service_Order_Line__c workDetail : currentWL ){
        
          
          DateTime dt = DateTime.valueOf(workDetail.SIG_Start_Date_Time_Device__c);
          System.debug('Work Detail Number: ' +workDetail.Name + '   #####     ' + 'DateTime :' + dt);

        }


If I take a look on my work details I see that Start Date/Time - Device is not the same with what I received in my system debug...
 
This is how it looks without any time conversion, its basically a text of DateTime.

User-added imageBut when I system debug this I get converted value:

User-added imageHow can I get the original value from the WEB and avoid the time conversion? Please help.. I'm stuck with this.

Hi, I created a trigger to populate a field on the Work Order Object.

SVMXC__SVMX_Event__c  = ServiceMax Event Object
SVMXC__Service_Order__c = Work Order Object

My trigger:

trigger secondTechnicianValidation on SVMXC__SVMX_Event__c (after update, after insert) {
    
    //store the Work Order id
    Set<ID> wo = new Set<ID>();
    
    for(SVMXC__SVMX_Event__c svmxEv : Trigger.New)
    {
        wo.add(svmxEv.SVMXC__Service_Order__c);

    }
    
    System.debug('woOrderId is: '+ wo);
    
    
    //-----------------Store the ServiceMaxEvents related to the current Work Order--------------------------------------//
    List<SVMXC__SVMX_Event__c> allEventsForAWo = [Select SVMXC__Service_Order__c, SVMXC__Technician__r.SVMXC__Salesforce_User__r.Email from SVMXC__SVMX_Event__c where SVMXC__Service_Order__c =: wo];
    System.debug('ServiceMax Events related to this Work Order are:  '+ allEventsForAWo );
    
    
    //----------------Store the emails of Technicians from these ServiceMax Events --------------------------------------//
    Set<String> emailTechniciansServiceEvents = new Set<String>();
    for(SVMXC__SVMX_Event__c smvxEvent : allEventsForAWo)
    {
         emailTechniciansServiceEvents.add(smvxEvent.SVMXC__Technician__r.SVMXC__Salesforce_User__r.Email);
    }
    System.debug('Emails of the technicians are: '+ emailTechniciansServiceEvents );
    
    // ---------------store the Work Order object which it needs to be updated with the emails of the technicians --------//
    List<SVMXC__Service_Order__c> storeWorkOrders  = new List<SVMXC__Service_Order__c>();
    for(Id woId : wo)
    {
        SVMXC__Service_Order__c order = new SVMXC__Service_Order__c();
        order.id = woId;
        storeWorkOrders.add(order);
    }
    System.debug('storeWorkOrders' + storeWorkOrders);
    
    //-------------------loop through each work order -----------------------------------------------//
    List<SVMXC__Service_Order__c> woToUpdate= new List<SVMXC__Service_Order__c>();
    for(SVMXC__Service_Order__c wos : storeWorkOrders){
         wos.TechniciansEmail__c = String.join(new List<String>(emailTechniciansServiceEvents), ', ');
         woToUpdate.add(wos);
    }
    System.debug('woToUpdate' + woToUpdate);
    
    //-------------------update the list-----------------------//
    if(!woToUpdate.IsEmpty()){
        update woToUpdate;
    }
}


Everything works fine with a single record when I edit the Service Max event... but... when I use data loader to mass update it doesnt work correctly.

This is my debug with a single record:

User-added image

Everything is fine as you can see.. Any idea why with data loader is not working correctly?

Hi, can someone guide me how can i cover atleast 75 of this class?
 
public class WorkOrderRelatedList{
    
    public SVMXC__Service_Order_Line__c[] WorkDetailList{get;set;}
    String u = UserInfo.getUserId();
    public WorkOrderRelatedList(ApexPages.standardController std){
        WorkDetailList=new SVMXC__Service_Order_Line__c[]{};
         string WorkOrderId=ApexPages.currentPage().getParameters().get('id');
        if(WorkOrderId==NULL){
            system.debug('No Id available');
        }
        else{
            SVMXC__Service_Order__c[] AccWL=new SVMXC__Service_Order__c[]{};
            AccWL=[Select id,  (select ID, Name, lastmodifieddate, SVMXC__Line_Type__c,SVMXC__Product__c, SVMX_PS_Consumed_Qty__c, SIG_SC_Description__c, SVMXC__Group_Member__c, 
                                       SVMX_PS_Customer_Start_Date__c, SVMX_PS_Customer_Start_Time__c, SVMX_PS_Customer_End_Time__c, SVMX_PS_Customer_End_Date__c, SIG_Duration_Hours__c
                                from SVMXC__Service_Order_Line__r where (SVMXC__Line_Type__c = 'Labor' AND  CreatedById =:  u) OR (SVMXC__Line_Type__c = 'Travel' AND  CreatedById =:  u ) OR SVMXC__Line_Type__c = 'Parts' )  
                  from SVMXC__Service_Order__c where id =:WorkOrderId];
            for( SVMXC__Service_Order__c c:AccWL ){
                for(SVMXC__Service_Order_Line__c obj:c.SVMXC__Service_Order_Line__r ){
                    WorkDetailList.add(obj);
                }
            }
        }
    }
}



I only covered 45%...

 

@isTest
class WorkOrderRelatedList_UT{

    @isTest
    static void testtMethod() 
    { 
          String u = UserInfo.getUserId();
          SVMXC__Service_Order__c woTest = new SVMXC__Service_Order__c();
          woTest.SVMXC__Priority__c = 'Normal';
          insert woTest;
          
          SVMXC__Service_Order__c wo = [Select ID from SVMXC__Service_Order__c where Id =: woTest.id];
         
        
         ApexPages.StandardController sc = new ApexPages.StandardController(woTest);
         WorkOrderRelatedList testWo     = new WorkOrderRelatedList(sc);
        
         PageReference pageRef = Page.WorkDetailRelatedList; // Add your VF page Name here
         pageRef.getParameters().put('id', String.valueOf(wo.Id));
         Test.setCurrentPage(pageRef);
         
         SVMXC__Service_Order_Line__c workDetail = new SVMXC__Service_Order_Line__c();
         workDetail.SVMXC__Service_Order__c = wo.Id;
         workDetail.RecordTypeId = '0121i000000Gs2VAAS';
         workDetail.SVMXC__Line_Type__c = 'Labor';
         
         insert workDetail;
        
        
    }
}


My visualforce page:

 

<apex:page standardController="SVMXC__Service_Order__c" extensions="WorkOrderRelatedList" tabStyle="SVMXC__Service_Order_Line__c" lightningStylesheets="true">
<style>
body .bPageBlock .pbBody .labelCol{
     float:left;
}
</style>
    
    <apex:pageBlock Title="My Work Details">
        
            <apex:pageBlockTable style="width:100%" value="{!WorkDetailList}" var="n" >
                <apex:column style="width:50px" headerValue="Line Number" value="{!n.Name}"/>
                <apex:column style="width:50px" headerValue="Line Type" value="{!n.SVMXC__Line_Type__c}" />
                <apex:column style="width:10px" headerValue="Part" value="{!n.SVMXC__Product__c}" />
                <apex:column style="width:1px" headerValue="Consumed Qty" value="{!n.SVMX_PS_Consumed_Qty__c}" />
                <apex:column style="width:10px" headerValue="SC Description" value="{!n.SIG_SC_Description__c}" />
                <apex:column style="width:10px" headerValue="Technician" value="{!n.SVMXC__Group_Member__c}" />
                <apex:column style="width:10px" headerValue="Reported Start Date" value="{!n.SVMX_PS_Customer_Start_Date__c}" />
                <apex:column style="width:10px" headerValue="Reported Start Time" value="{!n.SVMX_PS_Customer_Start_Time__c}" />
                <apex:column style="width:10px" headerValue="Reported End Date" value="{!n.SVMX_PS_Customer_End_Date__c}" />
                <apex:column style="width:10px" headerValue="Reported End Time" value="{!n.SVMX_PS_Customer_End_Time__c}" />
                <apex:column style="width:10px" headerValue="Duration(hours)" value="{!n.SIG_Duration_Hours__c}" />


           
   </apex:pageBlockTable>
        
        
    </apex:pageBlock>    
    
</apex:page>

​​​​​​​
Hi, I have this trigger which checks if I have a duplication(Dispatcher) in each Service Team.
trigger AvoidduplicateDispatcher on SVMXC__Dispatcher_Access__c (before insert) {

// for every new dispatcher created fetches the id of the service team selected in serviceTeamMap
    map<Id, Set<String>> serviceTeamMap = new map<Id, Set<string>>();
    for(SVMXC__Dispatcher_Access__c disp: trigger.new){
        if(disp.SVMXC__Service_Team__c!= null){
            serviceTeamMap.put(disp.SVMXC__Service_Team__c, new set<String>());
            system.debug('************'+serviceTeamMap);
        }
     }
     

    if(!serviceTeamMap.isEmpty()){
        for(SVMXC__Dispatcher_Access__c disp1: [Select Id, SVMXC__Dispatcher__c, SVMXC__Service_Team__c from SVMXC__Dispatcher_Access__c where SVMXC__Service_Team__c =: serviceTeamMap.keySet()]){
            serviceTeamMap.get(disp1.SVMXC__Service_Team__c).add(disp1.SVMXC__Dispatcher__c);
        }
        system.debug('******serviceTeamMap*****'+serviceTeamMap);
    }
    
    if(!serviceTeamMap.isEmpty()){
        for(SVMXC__Dispatcher_Access__c dispRec: trigger.new){
            system.debug('************'+dispRec.SVMXC__Dispatcher__c);
             Set<String> dispSet = serviceTeamMap.get(dispRec.SVMXC__Service_Team__c);
             system.debug('************dispSet '+dispSet);
             if(dispSet.contains(dispRec.SVMXC__Dispatcher__c)){
                 system.debug('************'+dispRec.SVMXC__Dispatcher__c);
                     dispRec.addError('You are already a dispatcher in this Service Team!');
             }  
             
        }
    }

}


This is my Test Class.

@isTest
public class AvoidduplicateDispatcher_UT {
    @isTest static void AvoiDuplicateDispatcher_TestMethod(){
        SVMXC__Dispatcher_Access__c dp = new SVMXC__Dispatcher_Access__c();
        dp.SVMXC__Dispatcher__c = '0051i0000012ogr';
        dp.SVMXC__Service_Team__c = 'a341i000000PBPY';
        insert dp;
        
        SVMXC__Dispatcher_Access__c dp1 = new SVMXC__Dispatcher_Access__c();
        dp1.SVMXC__Dispatcher__c = '0051i0000012ogr';
        dp1.SVMXC__Service_Team__c = 'a341i000000PBPY';
        Database.SaveResult sresult = Database.insert(dp1, false); 
    }
}


I have 100% coverage.

 

However in PROD when i want to migrate I have this error:

 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You are already a dispatcher in this Service Team!: []
Stack Trace: Class.AvoidduplicateDispatcher_UT.AvoiDuplicateDispatcher_TestMethod: line 12, column 1

How can i fix this guys?​​​​​​​

Hi, I have two objects.

Dispatcher(SVMXC__Dispatcher_Access__c) and Service Team(SVMXC__Service_Group__c).

The relationship between Dispatcher and the Service Team is many to one, in other words there can be multiple dispatchers associated to one Service Team. 

Here is a picture to make you understand:For example, we have this team AP-S-Indonesia FSE and we have 6 dispatchers related to this Service Team.
User-added image

I want to create a trigger to fetch all the Dispatchers related to this Service Team. Any suggestions?

Hi! I have created a trigger:

trigger SIG_permissionToEditAdminTasks on SIG_Administrative_Task__c (before update) {
       

         SVMXC__Service_Order__c queueOwner = new SVMXC__Service_Order__c();
        ApexPages.StandardController sc = new ApexPages.StandardController(queueOwner);
       SIG_QueueOwnerUpdate classQueue = new SIG_QueueOwnerUpdate(sc);
         
         
         
          public Set<String> memberIds = new Set<String>();
          String currentUserID = UserInfo.getUserId();
          SIG_Administrative_Task__c admTask = new SIG_Administrative_Task__c();
          
          
     
      //fetch the id of the creator of the record <start>
           Set<String> ownerIds = new Set<String>();
        for (SIG_Administrative_Task__c record : Trigger.New) {
            ownerIds.add(record.OwnerId);
             
        }
        
      // <end>
        
        List<Group> groups = [SELECT Id, (SELECT Id, UserOrGroupId FROM GroupMembers) FROM Group WHERE Id =: ownerIds];
        System.debug('####groups' + groups);    
        
          
         Set<String> memberIdsByGroupId = new Set <String>();
   
        //fetch the id's of the users from the the current owner queue  <start>
        for (Group groupRec : groups) {
         
            for (GroupMember member : groupRec.GroupMembers) {
                memberIds.add(member.UserOrGroupId);
            }
              
        }
        // <end>
       system.debug('memberIds123'+memberIds);

         for (SIG_Administrative_Task__c record : Trigger.New) {
            if((memberIds.contains(currentUserID) || record.createdById == UserInfo.getUserId() || record.OwnerID == UserInfo.getUserId() ))
            {
           
            }
            else
            {
               record.addError('You need to be the owner or to be inside of a queue to edit an Admin Task');
            }
        }
    

}

On this line I am trying to call a class in my trigger:

ApexPages.StandardController sc = new ApexPages.StandardController(queueOwner);
 SIG_QueueOwnerUpdate classQueue = new SIG_QueueOwnerUpdate(sc);


Everything looks fine.. but when I try to activate my trigger and do an update on a record i have this error:

User-added imageWhen i took a look in my class, line 73 this is what I see:

User-added imageHow can I call my class without getting this error?