• Cristian White
  • NEWBIE
  • 134 Points
  • Member since 2019
  • Admin

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 37
    Questions
  • 47
    Replies

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, 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>

​​​​​​​

We have an installed app integrated with Salesforce and we can generate PDF's with this app using HTML & CSS.

Now the problem is that my header keeps repeating on all pages which doesn't look nice and professional. Any ideas how can I keep my header to be only on the first page and not others?

 

Hi all,

I have the following error:

Error:Apex trigger countWL caused an unexpected exception, contact your administrator: countWL: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a1g1X000002QxttQAC; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a1g1X000002Qxtt) is currently in trigger countWL, therefore it cannot recursively update itself: []: Trigger.countWL: line 11, column 1


This is my trigger:

trigger countWL on SVMXC__Parts_Request_Line__c (before update, before insert) {


     //take all the parts line with their parts work detail
     List<SVMXC__Parts_Request_Line__c> partsWithWL = [SELECT Id,Name,(SELECT Id,Name FROM Work_Details__r WHERE SVMXC__Line_Type__c= 'Parts') FROM SVMXC__Parts_Request_Line__c WHERE Id IN :Trigger.New];
     System.debug('partsWithWL '+partsWithWL);
     
    
     for(SVMXC__Parts_Request_Line__c loopParts : partsWithWL ){
         loopParts.CountWLParts__c = loopParts.Work_Details__r.size();
         update loopParts;
         System.debug('loopParts.CountWLParts__c' + ' '+loopParts.CountWLParts__c);
        
     }
   
   
}

What I am doing wrong here? Why the trigger fails?​​​​​​​
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, we have 1 field which is Date/Time. The problem is that this field will get converted according to the user timezone. We have people working from all over the world and we don't want time conversion. We want if we select 7/6/2020 11:00 AM to be the same for everybody not to be converted on the current user timezone... is there a solution for this? I never worked with UTC timezone...

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?

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?

Hello, I want to update my attachments name after they are created. This works but the name of the Work Order(custom object) is not automatically. User-added imageThis is my attachments and you can see Related to : WO-0003061.

my trigger, it works if i hard code the name:

 

trigger SetTitleToAttachment on Attachment (before insert) { 


        for(Attachment a: Trigger.new){
          
            if(a.Name.startsWith('SIG_PM_Work_Order_Service_Report')){
                a.Name = 'Work Order name dynamically ';
            } else if (a.Name.startsWith('SIG_HandoverCheckList_Customer_To_SIG_Report')){
                a.Name = 'ServiceReport.pdf';
            }
            
        }


}


I want to on the line  a.Name = 'Work Order name dynamically '; to be instead of this string to be the name WO-0003061. How can i do this?

Please help. I would appreciate a lot :)

Hello,

I have a small trigger:
 

trigger SetTitleToAttachment on Attachment (after insert) { 

    
    //store the ID of the new attachment
    ID attachment;
    ID workOrder;

    
    
    for (Attachment att : Trigger.new) {
        attachment = att.ID;
        workOrder = att.ParentId;
       
        
    }
   Map<ID, SVMXC__Service_Order__c> wo =new Map<ID, SVMXC__Service_Order__c>( [SELECT ID, NAME, SVMX_PS_Ship_To_Name__c from SVMXC__Service_Order__c WHERE ID =: workOrder ]);


}


My question is: how can I access the fieds: Name and SVMX_PS_Ship_To_Name__c from this map?

I'm confused. 

Hello, I have a requirement to create a trigger to not allow users to edit records if they are not the creator OR if they are not the owner. Owner can be a simple user or a QUEUE.
 

This is what I wrote until now... my code is not working.

 

trigger permissionToEditAdminTasks on SIG_Administrative_Task__c (after update) {
  
      //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);    
        
          
        Map<String, Set<String>> memberIdsByGroupId = new Map<String, Set<String>>();
        
        //fetch the id's of the users from the the current owner queue  <start>
        for (Group groupRec : groups) {
            Set<String> memberIds = new Set<String>();
            for (GroupMember member : groupRec.GroupMembers) {
                memberIds.add(member.UserOrGroupId);
            }
               System.debug('####memberIds  ' + memberIds );   
        }
        // <end>
       

        for (SIG_Administrative_Task__c record : Trigger.New) {
            if (memberIdsByGroupId.get(record.OwnerId) != null && memberIdsByGroupId.get(record.OwnerId).contains(UserInfo.getUserId()))
            {
             
            }else{
                 record.addError('You have not permission for editing this record');
                  System.debug('record.OwnerId' + record.OwnerId);
            }
        }
    

}
I cannot edit the record no matter what, I don't know what is wrong in my code.. please help.
Hi! I want to create a class that will fetch the ID of an Account dynamic when I create a new record. We have a custom object named Account Change request. This object can be found in the related lists from Account. When user press to create a new Account Change Request I want to override it with my visualforce page, thus I would need to display the informations on my VF page from that Account. I tried to create by myself but it's not working..
 
public class MasterDataChange{


 public Account parentAccount{get; set;}
 public Account_Change_Request__c accChangeRequest;


 public MasterDataChange(ApexPages.StandardController controller){
    
  String parentAccId = ApexPages.currentPage().getParameters().get('id');
     if(parentAccId != null){
            parentAccount= [SELECT Id, Name FROM Account WHERE Id = :parentAccId limit 1];
                accChangeRequest.Account__c = parentAccount.Id;
            }
         
        } 

  
 public PageReference save(){
   insert accountChangeRequest;
   
    PageReference pg = new PageReference('/'+parentAccount.Id);
          pg.setRedirect(true);
         return pg;
 }
}

Account__c is my master-detail with the Account object.. please help.