• Sagar104
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 11
    Replies
Hi All

Im getting the below code error (A problem with the OnClick JavaScript for this button or link for the below code. aX63....(salesforce id) is not defined) for the execute javascript on the button 

Original Code :

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 

if('{!$Profile.Name}' == '1234') { 
alert("This feature is reserved for Administrators and Managers, Please Contact your supervisor..."); 
}else{ 
var r = confirm("Are you sure you want to reject this request? It will be removed from the Events Calendar."); 
if(r == true){ 
try{ 
var result; 
result = sforce.apex.execute("TechEvetLineRejectClass", "LineReject",{TELID:"{!Technician_Event_Lines__c.Id}"}); 
alert("Successfully Calendar Event Deleted... "); 
window.location.reload(); 

} catch(ex) { 
alert({!Technician_Event_Lines__c.Id}); 
alert(ex); 


}




SECONDLY i need to add a logic here that 
if Timeoff(a field with date value) is Less than todays date , Then need to throw an alert and the button on click should not work.

Kindly help
Hi All

Kindly help me here, i have an apex class for webservice, i require the test class to be completed.

The APEX CLASS is as follows;

global class Sendxxx {
    private static String workOrderId ;
    private static String workOrderStatus ;
    webService static void postToSAP(String orderStatus, String woId) { 
   system.debug('orderStatus'+orderStatus);
      If(orderStatus =='Complete' || orderStatus =='Partially Completed')
       { 
       system.debug('orderStatus'+orderStatus);
        workOrderId  = woId;
          workOrderStatus = orderStatus.tolowercase();
          //workOrderStatus = orderStatus;
        getAndParse();
        
    }
    else
    {
      system.debug('orderStatus'+orderStatus);
     }
      }
    
  global static void getAndParse() {
    
        HttpRequest req = new HttpRequest();
  
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        //String strname = 'Username';
       // String strpwd= 'pwd';
        //String SessionId = Userinfo.getSessionId();
        String strURL = System.URL.getSalesforceBaseURL().toExternalForm();
        req.setEndpoint('https://elastic.snaplogic.com:443/api/1/rest/slsched/feed/xxxx/xx/xxxrviceMax/SVMXC_SumEstimatedTime_Task?work_order_id='+workOrderId+'&state='+workOrderStatus);
        req.setHeader('authorization','Bearer owhBgvxxxxxxz');
        req.setTimeout(120000);
        req.setHeader('cache-control', 'no-cache');
        req.setMethod('GET');
        
        JSONGenerator gen = JSON.createGenerator(true);
            gen.writeStartArray();
            gen.writeStartObject();
            gen.writeStringField('SVMXC__Service_Order__c', workOrderId );
           gen.writeStringField('SVMXC__Order_Status__c',workOrderStatus );
            gen.writeEndObject();              
          gen.writeEndArray();
          String jsonOrders = gen.getAsString();
           System.debug('jsonOrders: ' + jsonOrders);
          req.setHeader('Content-Type', 'application/json');
          req.setHeader('Accept-Encoding', 'gzip');
           req.setBody(jsonOrders);
            req.setCompressed(true); // otherwise we hit a limit of 32000 
        try {
            res = http.send(req);
            
            if (res.getStatusCode() == 200 ) {
            
             System.debug('CALLOUOT SUCCESSFUL');
             System.debug('RESPONSE FROM CPQ 1111--->'+res.toString());
             System.debug('RESPONSE BODY--->'+res.getBody());
            }
        }             
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug('RESPONSE FROM CPQ'+res.toString());
        }
        
 }
 }
Assigining permission sets by apex trigger
Requirement : There are some fields on the object , we need to grant permissions to edit  based on the picklist values.( i have written validations rules at first but didnt work)
Scenerio:I ve made all the fields of the object read only in Profile. then created permission set to the fields for edit permission. now based on the profile name I want to assign the same permission set to the user though the trigger and class.
now it is working but when i edit the record for the first time permission set not being assigned, when i re edit the same record for the 2nd time , then permission set is getting assigned. please let me know what is the issue here.

CLASS

public class PSAclass 
{
 @future
  public static void assignPSA()
   {
     List<PermissionSetAssignment> psa1 = new List<PermissionSetAssignment>();
        String pf=[Select Id,Name from Profile where Id=:UserInfo.getProfileId()].Name;

    if(pf=='profile1' || pf == 'profile2' || pf=='profile3')
        {
            PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = '0PS3C0000004GLCWA2',AssigneeId = UserInfo.getUserId());
                psa1.add(psa); 
            
        }
        else if(pf=='profile4')
        {       
               PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = '0PS3C0000004GLW',AssigneeId = UserInfo.getUserId());
               psa1.add(psa); 
        }
    insert psa1;
   }
        
}

TRIGGER

trigger PSA_on_WO on Service_Order__c (before update)
{
    
    for ( Service_Order__c wo : trigger.new)
          {
               
               if(wo.Order_Status__c.equalsIgnoreCase('Draft') && wo.Order_Type__c.equalsIgnoreCase('FS'))
               {
                 PSAclass.assignPSA();
                   }
          }
}
Assigining permission sets by apex trigger
Requirement : There are some fields on the object , we need to grant permissions to edit  based on the picklist values.( i have written validations rules at first but didnt work)
Scenerio:I ve made all the fields of the object read only in Profile. then created permission set to the fields for edit permission. now based on the profile name I want to assign the same permission set to the user though the trigger.but it is not getting assigned. kindly assist what changes should be done?

Trigger Attached

trigger PSA_on_WO on Service_Order__c (before update)
    {
    if(Trigger.isBefore)
    {
      if(Trigger.isUpdate)
      {
          for ( Service_Order__c wo : trigger.new)
             {
                  id id1 = userinfo.getUserId();
                 id id2 = userinfo.getProfileId();
                String pf=[Select Id,Name from Profile where Id=:id2].Name;
              
              PermissionSetAssignment[] psa1 = new List<PermissionSetAssignment>();

              system.debug('profile ----> '+pf);
              system.debug('id1 ----> '+id1);
              system.debug('order status--->'+wo.Order_Status__c);
              system.debug('order type--->'+wo.Order_Type__c);
                  if(wo.Order_Status__c.equalsIgnoreCase('Draft') 
                           && wo.Order_Type__c.equalsIgnoreCase('FS'))
                 {
                       if(pf=='profile1' || pf == 'profile2' || pf=='profile3')
                    {
                         PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = '0PS3C0000004GLCWA2',AssigneeId = id1);
                 psa1.add(psa);        
                                   system.debug('permission set id----->' +psa.PermissionSetId);
                          system.debug('assignid id----->' +psa.AssigneeId);
                    }
                    else if(pf=='profile4')
                    {
                    PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = '0PS3C0000004GLW',AssigneeId = id1);
                     psa1.add(psa); 
                    }  
              
                   }
             insert psa1;
        }
    }
    }
}
Need to create a new report type has been requested linking  two objects "X" & "Y" . This report should contain all "X" objects as well as the fields associated to them by a common Sales Order number.
The link between these two objects should be as follows:
Order Number ("X") = SAP ID ("Y")
NOTE: Order Number will have 3 leading zeroes where as SAP ID will not, some logic needs to applied through the report link to remove these zeroes to ensure the link works properly.

HOW do i achieve it.. kindly suggest as im new to it
Profile: ES ServiceMax Manager ----
Field name : Service Description----
Order status (picklist type ) : Draft , pending, complete ,invoiced , cancelled

i want to write a validation rule , so that Service description should be editable it is in :
Draft - yes
Pending - yes
Complete - No
Invoived - No
Cancelled - No

How do i achieve it.. also i have a list of excel file from client which is having more no of Fields and the values goes on changing on the picklist values [![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/zxMoO.jpgExample
Im a newbie , On click of a custom button i need message to popup like xyz , but it shoul have ok or cancel.. If ok then it should proceed to the  operation , if cancell then just no action
Error Message: line 100, column 55: Constructor not defined: [TechnicianEventController.TimeOffDetails].<Constructor>(String, Date, String, String, String)

Class:

/**
* The TechnicianEventController_Test is test class for TechnicianEventController class which provides a feature  that allow FSRs to
* Apply the Time Off features 
*
* @author       Divya Navuluru
* @Email        divya1.navuluru@ge.com
* @version      1.0
* @since        2015-June-12
*/
@isTest(Seealldata = true )
Private  class TechnicianEventController_Test  {
     static testMethod void testmethod1() {
      
              Profile pf = [Select Id from Profile where Name = 'System Administrator'];
              User u =[Select id from User where id =: UserInfo.getUserId()];
              String strRecordTypeId = [Select Id From RecordType Where SobjectType = 'SVMXC__Service_Group__c' and Name = 'Technician'].Id;
              
                //Inserting service Team  
             SVMXC__Service_Group__c sgrp = new SVMXC__Service_Group__c();
              sgrp.Name = 'test name';
              sgrp.SVMXC__Group_Type__c = 'Internal';
              sgrp.Service_Team_Leader__c = u.id;   
              sgrp.RecordTypeId = strRecordTypeId;
              insert sgrp;
              
             //Inserting Liquidation Master
             Liquidation_Master__c LM = New Liquidation_Master__c();
              LM.Name= '227';
              LM.Currency__c='USD';
              LM.Sales_Org__c='B227';
              LM.Tax_Code__c='v0';
              LM.Trading_Partner__c='22700';
              insert LM;
              
             //Inserting Technician
             SVMXC__Service_Group_Members__c sgm = New SVMXC__Service_Group_Members__c();
              sgm.Name='test service team';
              sgm.SVMXC__Email__c ='raviasdasdasdasdasd@bs.com';   
              sgm.SVMXC__Service_Group__c = sgrp.id;
              sgm.SVMXC__Salesforce_User__c=u.id;
              sgm.Technician_Company_Code__c=LM.iD;
              //sgm.RecordTypeId = strRecordTypeId;
              insert sgm;  
     
            Technician_Event__c te=new Technician_Event__c();
            te.Subject__c   ='Vacation';
            te.Start__c =system.today();
            te.End__c= system.today()+2;
         te.GEW_On_Behalf_Of__c=u.id;
            te.Technician_Equipment__c=sgm.id;  
            try{
              insert te;
              }catch(Exception e){
             
               }    
        
            Integer toH = 0 ; 
            Integer totalHrs =  5;
         
            Technician_Event_Lines__c tel=new Technician_Event_Lines__c();
            tel.Technician_Event__c=te.id;
            tel.Total_Time_Off_Hours__c = 5;
            tel.Time_Off_Date__c = System.today();
            tel.Time_Off_Start_Time__c= '08:00 AM';
            tel.Time_Off_End_Time__c= '01:00 PM';
            try{
              insert tel;
              }catch(Exception e){
             
               }    
        
            Technician_Event_Lines__c tel1=new Technician_Event_Lines__c();
            tel1.Technician_Event__c=te.id;
            tel1.Total_Time_Off_Hours__c = 5;
            tel1.Time_Off_Date__c = System.today()+1;
            tel1.Time_Off_Start_Time__c= '12:00 PM';
            tel1.Time_Off_End_Time__c= '05:00 PM';
             try{
              insert tel1;
              }catch(Exception e){
             
               }    
                  Technician_Event_Lines__c tel2=new Technician_Event_Lines__c();
            tel2.Technician_Event__c=te.id;
            tel2.Total_Time_Off_Hours__c = 1;
            tel2.Time_Off_Date__c = System.today()+2;
            tel2.Time_Off_Start_Time__c= '02:00 PM';
            tel2.Time_Off_End_Time__c= '01:00 PM';
             try{
              insert tel2;
              }catch(Exception e){
             system.debug('To Hours Should be greater than From Hours'+e.getMessage());
               }   
        
         ApexPages.StandardController std1 = new ApexPages.StandardController(te);
         TechnicianEventController TEC=new TechnicianEventController(std1);
         TEC.stDat = System.today();
         TEC.edDat = System.today()+7;
         //TEC.u = UserInfo.getUserId();
         TechnicianEventController.TimeOffDetails t = new TechnicianEventController.TimeOffDetails('SickLeave' ,System.today() ,'Sunday'  ,'--None--' ,'--None--') ; 
          TechnicianEventController.TimeOffDetails t1 = new TechnicianEventController.TimeOffDetails('Vacation' ,System.today() ,'Monday'  ,'9:00 AM' ,'12:00 AM') ; 
           TechnicianEventController.TimeOffDetails t2 = new TechnicianEventController.TimeOffDetails('Vacation' ,System.today() ,'Tuesday'  ,'9:00 AM' ,'--None--');
           TechnicianEventController.TimeOffDetails t3 = new TechnicianEventController.TimeOffDetails('SickLeave' ,System.today() ,'Wednesday'  ,'--None--' ,'12:00 AM') ;    
         TEC.showSection();
         try{
             
             TEC.saveTimeOff();    
         
         }catch(Exception e){
             
         }      
     }

 }
 
Hi All

Im getting the below code error (A problem with the OnClick JavaScript for this button or link for the below code. aX63....(salesforce id) is not defined) for the execute javascript on the button 

Original Code :

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 

if('{!$Profile.Name}' == '1234') { 
alert("This feature is reserved for Administrators and Managers, Please Contact your supervisor..."); 
}else{ 
var r = confirm("Are you sure you want to reject this request? It will be removed from the Events Calendar."); 
if(r == true){ 
try{ 
var result; 
result = sforce.apex.execute("TechEvetLineRejectClass", "LineReject",{TELID:"{!Technician_Event_Lines__c.Id}"}); 
alert("Successfully Calendar Event Deleted... "); 
window.location.reload(); 

} catch(ex) { 
alert({!Technician_Event_Lines__c.Id}); 
alert(ex); 


}




SECONDLY i need to add a logic here that 
if Timeoff(a field with date value) is Less than todays date , Then need to throw an alert and the button on click should not work.

Kindly help
Hi All

Kindly help me here, i have an apex class for webservice, i require the test class to be completed.

The APEX CLASS is as follows;

global class Sendxxx {
    private static String workOrderId ;
    private static String workOrderStatus ;
    webService static void postToSAP(String orderStatus, String woId) { 
   system.debug('orderStatus'+orderStatus);
      If(orderStatus =='Complete' || orderStatus =='Partially Completed')
       { 
       system.debug('orderStatus'+orderStatus);
        workOrderId  = woId;
          workOrderStatus = orderStatus.tolowercase();
          //workOrderStatus = orderStatus;
        getAndParse();
        
    }
    else
    {
      system.debug('orderStatus'+orderStatus);
     }
      }
    
  global static void getAndParse() {
    
        HttpRequest req = new HttpRequest();
  
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        //String strname = 'Username';
       // String strpwd= 'pwd';
        //String SessionId = Userinfo.getSessionId();
        String strURL = System.URL.getSalesforceBaseURL().toExternalForm();
        req.setEndpoint('https://elastic.snaplogic.com:443/api/1/rest/slsched/feed/xxxx/xx/xxxrviceMax/SVMXC_SumEstimatedTime_Task?work_order_id='+workOrderId+'&state='+workOrderStatus);
        req.setHeader('authorization','Bearer owhBgvxxxxxxz');
        req.setTimeout(120000);
        req.setHeader('cache-control', 'no-cache');
        req.setMethod('GET');
        
        JSONGenerator gen = JSON.createGenerator(true);
            gen.writeStartArray();
            gen.writeStartObject();
            gen.writeStringField('SVMXC__Service_Order__c', workOrderId );
           gen.writeStringField('SVMXC__Order_Status__c',workOrderStatus );
            gen.writeEndObject();              
          gen.writeEndArray();
          String jsonOrders = gen.getAsString();
           System.debug('jsonOrders: ' + jsonOrders);
          req.setHeader('Content-Type', 'application/json');
          req.setHeader('Accept-Encoding', 'gzip');
           req.setBody(jsonOrders);
            req.setCompressed(true); // otherwise we hit a limit of 32000 
        try {
            res = http.send(req);
            
            if (res.getStatusCode() == 200 ) {
            
             System.debug('CALLOUOT SUCCESSFUL');
             System.debug('RESPONSE FROM CPQ 1111--->'+res.toString());
             System.debug('RESPONSE BODY--->'+res.getBody());
            }
        }             
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug('RESPONSE FROM CPQ'+res.toString());
        }
        
 }
 }
Assigining permission sets by apex trigger
Requirement : There are some fields on the object , we need to grant permissions to edit  based on the picklist values.( i have written validations rules at first but didnt work)
Scenerio:I ve made all the fields of the object read only in Profile. then created permission set to the fields for edit permission. now based on the profile name I want to assign the same permission set to the user though the trigger.but it is not getting assigned. kindly assist what changes should be done?

Trigger Attached

trigger PSA_on_WO on Service_Order__c (before update)
    {
    if(Trigger.isBefore)
    {
      if(Trigger.isUpdate)
      {
          for ( Service_Order__c wo : trigger.new)
             {
                  id id1 = userinfo.getUserId();
                 id id2 = userinfo.getProfileId();
                String pf=[Select Id,Name from Profile where Id=:id2].Name;
              
              PermissionSetAssignment[] psa1 = new List<PermissionSetAssignment>();

              system.debug('profile ----> '+pf);
              system.debug('id1 ----> '+id1);
              system.debug('order status--->'+wo.Order_Status__c);
              system.debug('order type--->'+wo.Order_Type__c);
                  if(wo.Order_Status__c.equalsIgnoreCase('Draft') 
                           && wo.Order_Type__c.equalsIgnoreCase('FS'))
                 {
                       if(pf=='profile1' || pf == 'profile2' || pf=='profile3')
                    {
                         PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = '0PS3C0000004GLCWA2',AssigneeId = id1);
                 psa1.add(psa);        
                                   system.debug('permission set id----->' +psa.PermissionSetId);
                          system.debug('assignid id----->' +psa.AssigneeId);
                    }
                    else if(pf=='profile4')
                    {
                    PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = '0PS3C0000004GLW',AssigneeId = id1);
                     psa1.add(psa); 
                    }  
              
                   }
             insert psa1;
        }
    }
    }
}
Need to create a new report type has been requested linking  two objects "X" & "Y" . This report should contain all "X" objects as well as the fields associated to them by a common Sales Order number.
The link between these two objects should be as follows:
Order Number ("X") = SAP ID ("Y")
NOTE: Order Number will have 3 leading zeroes where as SAP ID will not, some logic needs to applied through the report link to remove these zeroes to ensure the link works properly.

HOW do i achieve it.. kindly suggest as im new to it
Im a newbie , On click of a custom button i need message to popup like xyz , but it shoul have ok or cancel.. If ok then it should proceed to the  operation , if cancell then just no action