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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 30
    Questions
  • 44
    Replies
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?

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 :)

Hi, we have installed a managed package in Salesforce and it is basically an app and when we enter on that app the link changes.. is there a way to get url from that app?

 

User-added image

I want to get this url:https://sig-cb--full--svmxc.cs88.visual.force.com/apex/SVMXC__OPDOC_Delivery?SVMX_recordId=a391i000000CjVdAAK&SVMX_processId=SIG_PM_Work_Order_Service_Report&SVMX_retURL=/a391i000000CjVdAAK

 

Is that possible?

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.
Hello, we want to migrate every button from classic to lightning and I'm stuck with this particular button. In classic it works fine but when I switch to Lightning its not working. Simply just remain in the stage of 'Loading...' and the page remains blank.. 

This is how my button and VF page looks:

User-added imageUser-added image
 
<apex:page standardController="Account" lightningStylesheets="true">
    <c:QV_Jump QVURL="https://delinvmas624/QvAJAXZfc/opendoc.htm?document=CRM/CRM_Price_Waterfall.qvw&host=delinvmas624&select=CRM_ACCOUNT,{!Account.SAP_Customer_ID__c}&select=CRM_ACCOUNT_2,{!Account.SAP_Customer_ID__c}"
               QVURL_mobile="https://delin-qv-mobile-idp-prod.sig.dom/QvAJAXZfc/opendoc.htm?document=CRM/CRM_Price_Waterfall.qvw&host=delinvmas369&select=CRM_ACCOUNT,{!Account.SAP_Customer_ID__c}&select=CRM_ACCOUNT_2,{!Account.SAP_Customer_ID__c}" />
</apex:page>
Anyone has an idea why it's not loading in Lightning?
 

Hello, I wrote a trigger to check if the url = 'https://sig-cb--Full.cs88.my.salesforce.com' and the profile of the current user is a specific profile (SIG-FSM-Super User) and if so the trigger shows an error message and also an image which I included in the addError function, it looks like this:

trigger ContactCreationForServiceMaxUsers on Contact (Before insert) {
   
       String baseURL = String.valueof(URL.getSalesforceBaseUrl());
      
       system.debug('<<baseURL>>' + baseURL);
       Boolean isBaseURL = baseURL.contains('https://sig-cb--Full.cs88.my.salesforce.com');
       System.debug(' >> String.valueof(URL.getSalesforceBaseUrl()) >>'+baseURL ); 
       User currentUser = [SELECT Id, Profile.Name FROM USER WHERE Id =:UserInfo.getUserId()]; 
      
       Contact c = new Contact(); 
      
       System.debug(' >> isBaseURL >>'+isBaseURL ); 
       System.debug(' >> currentUser.Profile.Name>>'+currentUser.Profile.Name ); 
   
     for(Contact c : Trigger.New){ 
          if(isBaseURL == TRUE  && currentUser.Profile.Name == 'SIG-FSM-Super User'){
           c.addError(' <p style="color:red; font-size: 20px;">Service contact creation is only allowed from “Account” tab using the blue button “Create Contact” after selecting a account”</p><img id="theImage" src="https://sig-cb--full--c.cs88.content.force.com/servlet/servlet.FileDownload?file=0159E0000002tNp" width="850px" height="100px" alt="Description of image here"/> ', false); 
          } 
     } 
}


Can anyone help me with how to build the test class for the trigger? At least theoretical.

1. First I need to create a contact
2. I need to create a user with a profile = 'super-user'
3. somehow i need to check the addError function..

Something like 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.