• Luke Higgins 23
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 13
    Questions
  • 9
    Replies
I need help on writing a test class for the following- 
@RestResource(urlMapping='/approve/*')
global with sharing class exAppClass {
  jstcl__TG_Timesheet__c ts = new jstcl__TG_Timesheet__c();
        // GET request
       @HttpPost
        global static String doGet() {
        RestRequest req = RestContext.request;   
          String secid = req.params.get('id');
          String approverId = req.params.get('appid');
          String ipString = req.params.get('ip');
          System.debug(secid);
          String alreadyApproved = 'expired';
          String error = 'error';
          String success = 'approved';
          String primApprover;
          String secApprover;
          jstcl__TG_Timesheet__c ts;
          ts = [SELECT Id, jstcl__Week_Ending__c, jstcl__Status__c, jstcl__Placement__r.jstcl__SecondaryApprover__c, jstcl__Placement__r.jstcl__TimecardApprover__c FROM jstcl__TG_Timesheet__c WHERE Id = :tsid FOR UPDATE];
          primApprover = String.valueOf(ts.jstcl__Placement__r.jstcl__TimecardApprover__c);
          secApprover = String.valueOf(ts.jstcl__Placement__r.jstcl__SecondaryApprover__c);  
          if (ts != null && ts.jstcl__Status__c == 'Approved' && (primApprover == approverId || secApprover == approverId )) {
            return alreadyApproved;
          } else if(ts != null && ts.jstcl__Status__c == 'Submitted' && (primApprover == approverId || secApprover == approverId)){
            try{
                insertLog(ts, approverId, ipString);
                ts.jstcl__Status__c = 'Approved';
                update ts;   
            } catch(Exception e) {
                System.debug('Exception caught: ' + e.getMessage()); 
                return error;   
            } 
          return success;
          }else {
          return error;
          }
        }
     
        private static Express_Approval_Log__c insertLog(jstcl__TG_Timesheet__c ts, Id approverId, String ip){
          Express_Approval_Log__c log = new Express_Approval_Log__c();
          log.Name = 'EAL '+ts.jstcl__Week_Ending__c;
          log.Timesheet__c = ts.Id;
          log.Approval_Date_Time__c= DateTime.now();
          log.Status__c = 'Approved';
          log.Timesheet_Approver__c = approverId;
          log.IP_Address__c = ip;
         try{
            insert log;
         }catch(Exception e) {
            System.debug('Exception caught: ' + e.getMessage());    
        } 
          return log;
      }
}

Test class so far:

@isTest
private class exAppClassTest {
    static testMethod void  updateMethodTest(){
     jstcl__TG_Timesheet__c ts = createTestRecord();
        
     String JSONMsg = '{"id" : "'+ts.Id +'","ip":"12:34:00:00","appid":"a4t3700000345ZC4AAO}';

     RestRequest req = new RestRequest();
     RestResponse res = new RestResponse();
     
     req.requestURI = '/services/apexrest/abc/xyz/';  //Request URL
     req.httpMethod = 'POST';//HTTP Request Type
     req.requestBody = Blob.valueof(JSONMsg);
     
     RestContext.request = req;
     RestContext.response= res;
     
     Test.startTest();
         exAppClass.doGet();
     Test.StopTest();   
 }
 
 // Helper method to create test data
 static jstcl__TG_Timesheet__c createTestRecord() {
     // Create test record
     Contact con=new Contact(
        FirstName='fname',
        LastName = 'lname',
        Email = 'email@gmail.com',
        Phone = '9743800309'); 
    insert con; 
    ts2__Placement__c plc = new ts2__Placement__c();
    plc.jstcl__SecondaryApprover__c = con.Id;
    plc.jstcl__TimecardApprover__c = con.Id;
    insert plc;
    jstcl__TG_Timesheet__c ts =new jstcl__TG_Timesheet__c ();
    date mydate = date.parse('12/27/2009');
    ts.jstcl__Status__c='Test';
    ts.jstcl__Week_Ending__c=mydate ;
    insert ts;
    Express_Approval_Log__c log = new Express_Approval_Log__c();
    log.Timesheet__c = ts.Id;
    log.name = 'Test';
    log.Timesheet_Approver__c = con.Id;
    log.Status__c = 'Approved';
    insert log;
     return ts ;
 }
}
After clicking a link to create a record, I'm trying to redirect to a landing page. Currently, it just takes the user to an XML file tree. Here is the code I currently have - 
 
@RestResource(urlMapping='/approve/*')
global with sharing class exAppClass {
  jstcl__TG_Timesheet__c ts = new jstcl__TG_Timesheet__c();
        // GET request
       @HttpGet
        global static jstcl__TG_Timesheet__c doGet() {
          RestRequest req = RestContext.request;
          RestResponse res = RestContext.response;
          String tsid = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

          jstcl__TG_Timesheet__c ts = [SELECT Id, jstcl__Week_Ending__c FROM jstcl__TG_Timesheet__c WHERE Id = :tsid];
          getCalloutResponseContents();
          insertLog(ts);
          return ts;
        }
        private static Express_Approval_Log__c insertLog(jstcl__TG_Timesheet__c ts){
          Express_Approval_Log__c log = new Express_Approval_Log__c();
          log.Name = 'EAL '+ts.jstcl__Week_Ending__c;
          log.Timesheet__c = ts.Id;
          log.Approval_Date_Time__c= DateTime.now();
          log.Status__c = 'Approved';
          insert log;
          return log;
      }
      public static PageReference getCalloutResponseContents() {
        PageReference pageRef = new PageReference('https://testURL.com');
      return pageRef;
        }
        
}

The getCalloutResponseContents() is not redirecting to the URL provided
I'm trying to grab the record id of a Timesheet and create a related Approval Log object through a GET request. When testing, the SOQL query is returning no results although I know that the string inserted is a valid Timesheet id

Apex Class:
@RestResource(urlMapping='/approve/*')
global with sharing class exAppClass {
  jstcl__TG_Timesheet__c ts = new jstcl__TG_Timesheet__c();
        // GET request
       @HttpGet
        global static jstcl__TG_Timesheet__c doGet() {
          RestRequest req = RestContext.request;
          String tsid = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

          System.debug(tsid);
          jstcl__TG_Timesheet__c ts = [SELECT Id, jstcl__Week_Ending__c FROM jstcl__TG_Timesheet__c WHERE Id = :tsid];
          insertLog(ts);
          return ts;
        }
        private static Express_Approval_Log__c insertLog(jstcl__TG_Timesheet__c ts){
          Express_Approval_Log__c log = new Express_Approval_Log__c();
          log.Name = 'EAL '+ts.jstcl__Week_Ending__c;
          log.Timesheet__c = ts.Id;
          insert log; 
          return log;
      }
  }

 
I have a Timesheet object and once the Timesheet status field is changed to "Submitted", it kicks off an automated workflow that sends an email to the Contact associated with the Timesheet record (Timesheet Approver). The Classic Email Template (HTML) I created, grabs the Timesheet record ID from the workflow and appends it to a Site URL that is sent in the email body. Once this link is clicked, it's supposed to take you to the Visualforce page enabled on the site and the Apex class associated with the VF page switches the Timesheet status to "Approved" when the link is clicked. Currently, once selecting the link, the URL requires a sign-in to make the update. The main goal is to be able to send an email to external contacts where they can quickly approve timesheets from clicking a link in an email and not have to login anywhere. It all works perfectly if you are signed in, but that is the main thing I'm trying to avoid. If you could help me correctly set up this Site/VF page to be visible and functional for public use, or even an entirely different way to do this, that would be greatly appreciated!
I am trying to send email to contacts through an email template and I want to append the Contact ID on a URL. I can get it to work within Salesforce but once the email is sent to an external email address, the Contact ID portion of the URL is missing.

Visualforce Email Template:
<messaging:emailTemplate subject="Test" recipientType="Contact" >
    <messaging:htmlEmailBody >
       <apex:variable var="c" value="{!recipient}" />
        <html>
            <body>
            <p>Hello,</p>

            <p><a href="www.test.com/ContactId={!recipient.Id }">Linkr</a></p>

            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 
I am trying to count the number of placements on each account. I thought about using a trigger and flow to do this but I think there are too many placements for this to work. This batch class I wrote is returning an error that I am uncertain how to get around. "Invalid bind expression type Account for Column of type Id" on line 9
 
public class plcCounterOnAcct implements Database.Batchable<sObject>, Database.Stateful {

    public Database.QueryLocator start(Database.BatchableContext bc) {
        String query = 'SELECT Id, Name FROM Account';
    return Database.getQueryLocator(query);
    }
    public void execute(Database.BatchableContext BC, List<Account> acctList){
        for(Account acc : acctList){
            List<ts2__Placement__c> plcOnAcct = [SELECT Id FROM ts2__Placement__c WHERE ts2__Client__c = :acc];
            acc.Total_Placement_Count__c = plcOnAcct.size();
        }
        try {
        	// Update the Account Record
            update acctList;
        
        } catch(Exception e) {
            System.debug(e);
        }
    }
    public void finish(Database.BatchableContext BC){
    }
}

 
I am querying timesheets__c and looking to update the contact associated to the timesheet (timecardApprover__c) that is held in the parent object placement__c. I am able to get a list of ids of the contact I need to update but I can't figure out how to to update the field current_timesheet_status__c associated with the contact. 
public with sharing class contFlag {
    public contFlag() {

        List<String> timecardApproverIds = new List<String>();
        Set<Id> setofIds = new Set<Id>();

    for(jstcl__TG_Timesheet__c ts : [SELECT Placement__r.TimecardApprover__c FROM Timesheet__c WHERE Placement__r.Status__c = 'Active' AND Status__c = 'Pending']){
              timecardApproverIds.add(String.valueOf(ts));
        }

    for(String a : timecardApproverIds){
            setofIds.add(Id.valueOf(a));
        }
    for(Id c : setofIds){
        c.Current_Timesheet_Status__c = 'Pending';
        // returns error of variable does not exist due to it not being for the contact object
        }
    }
}


 

I am trying to pass 2 object ids to an apex controller in order to use for a SOQL query. I then want to pass the list created in the SOQL query back to the javascript controller. There, I want to see if the list is empty or not and fire a message depending on the result.

component:

<aura:component  implements="flexipage:availableForRecordHome,force:hasRecordId,flexipage:availableForAllPageTypes,force:lightningQuickAction,force:appHostable" controller="getPTM" access="global">
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="plc" type="ts2__Placement__c"/>
    <aura:attribute name="user" type="String"/>
    <aura:attribute name="plan" type="String"/>
     <aura:attribute name="cpaList" type="jstcl__TG_Commission_Plan_Assignment__c[]"/>
    <aura:attribute name="parentId" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"></aura:handler>
	<aura:handler event="c:selectedsObjectRecordsEvent" action="{!c.submitIt}" />
    <lightning:recordEditForm aura:id="editfrm" recordId="{!v.recordId}" objectApiName="jstcl__PlacementTeamMember__c" onload="{!c.onloadrec}" onsuccess="{!c.successsave}"  > 
        <div class="slds-grid slds-gutters slds-p-horizontal_small">  
            <div class="slds-p-around_xx-small slds-size_2-of-8">   <lightning:inputField aura:id="plc" fieldName="jstcl__Placement__c" value="{!v.parentId}"/></div>
            <div class="slds-p-around_xx-small slds-size_2-of-8">   <lightning:inputField aura:id="user" fieldName="jstcl__User__c" value="{!v.user}"/></div>
            <div class="slds-p-around_xx-small slds-size_2-of-8">   <lightning:inputField aura:id="plan" fieldName="jstcl__CommissionPlan__c" value="{!v.plan}"/></div>
            <div class="slds-p-around_xx-small slds-size_1-of-8">   <lightning:inputField aura:id="split" fieldName="jstcl__SplitPercent__c"/></div>
            <div class="slds-p-around_xx-small slds-size_1-of-8 slds-m-top_large">   <lightning:button variant="brand"
			iconName="utility:add" label="Add User" title="Add User" onclick="{! c.greyOut }" /></div>
        </div>
    </lightning:recordEditForm>
</aura:component>
Component Controller
doInit: function(component, event, helper) {
        //Create the action
       var action = component.get("c.plcGetCPA");
       var user = component.get("v.user");
        var plan = component.get("v.plan");
        action.setParams({
            "user" : user,
            "plan" : plan
        });
        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
               component.set("v.cpaList", response.getReturnValue());
            }
            else { console.log("Failed with state: " + state); }
        });
        // Send action off to be executed
        $A.enqueueAction(action);
    },
    greyOut : function(component , event , helper){
        var toastEvent = $A.get("e.force:showToast");
        var user = component.get("v.user");
        var plan = component.get("v.plan");
        var cpaList = component.get("v.cpaList");
		var cpaLength = cpaList.length;
        component.set("v.isOpen", !component.get("v.isOpen"));
        
        if(cpaLength > 0){
        toastEvent.setParams({
            title : 'Success',
            message:'Commission Plan matches.' + cpaList +" -------- "+ plan,
            duration:'5000',
            key: 'info_alt',
            type: 'error',
            mode: 'pester' });
        toastEvent.fire();}   
     else { toastEvent.setParams({
            title : 'Error',
            message:'Commission Plan does not match the user.' + user +' '+ plan,
            duration:'5000',
            key: 'info_alt',
            type: 'error',
            mode: 'pester' });
        toastEvent.fire();}    
    }

Apex Controller:
public class getPTM {
AuraEnabled
    public static List<jstcl__TG_Commission_Plan_Assignment__c> plcGetCPA(List<Id> userId, List<Id> planId){
       
        List<jstcl__TG_Commission_Plan_Assignment__c> cpaList= new List<jstcl__TG_Commission_Plan_Assignment__c>();
        cpaList = [SELECT Id
                   FROM jstcl__TG_Commission_Plan_Assignment__c 
                   WHERE jstcl__User__r.Id IN :userId AND jstcl__Commission_Plan__r.Id IN :planId];
       
    return cpaList;
        
    }

}

 
Hi,
I am trying to get a test class written for this trigger that adds a child record after the creation of the parent record. I am getting the following error -
"System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, jstcl.PlacementTeamMember: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.jstcl.PlacementTeamMemberTriggerHandler.validateTeamMembers: line 14, column 1
Trigger.jstcl.PlacementTeamMember: line 2, column 1: []"

trigger:
trigger autoAddNAM_VAM on ts2__Placement__c (after insert) {
    List<jstcl__PlacementTeamMember__c> teamMems = new List<jstcl__PlacementTeamMember__c>();
     Set<Id> tsClientSet = new Set<id>();
      Map<ID, Account> tsClientmap = new Map<ID, Account> ();   // Check the API Name of ts2__Client__c object
 for(ts2__Placement__c newTeamMem : Trigger.New)
    {
        
        if(newTeamMem.ts2__Client__c != null)
        {
            
            tsClientSet.add(newTeamMem.ts2__Client__c);
        }
    }
    
    if(tsClientSet.size() > 0)
    {
        tsClientmap = new Map<ID, Account>([SELECT Id, VAM_or_NAM_Member__c from Account where Id IN: tsClientSet]);
    }
    for(ts2__Placement__c newTeamMem : Trigger.New){

        if(tsClientmap.Containskey(newTeamMem.ts2__Client__C))
        {
                      
  try{ 
            if (tsClientmap.get(newTeamMem.ts2__Client__C).VAM_or_NAM_Member__c != null ){
                teamMems.add(new jstcl__PlacementTeamMember__c(
                        jstcl__Placement__c = newTeamMem.Id,
                        jstcl__User__c = tsClientmap.get(newTeamMem.ts2__Client__C).VAM_or_NAM_Member__c,
                        jstcl__CommissionPlan__c = [Select jstcl__Commission_Plan__c
                                                    FROM jstcl__TG_Commission_Plan_Assignment__c 
                                                    WHERE jstcl__Commission_Plan__r.Name LIKE '%Plan%' AND jstcl__User__c = :tsClientmap.get(newTeamMem.ts2__Client__C).VAM_or_NAM_Member__c].jstcl__Commission_Plan__c,
                        jstcl__SplitPercent__c = 100));
            }
  }catch(exception e){
       System.debug('The following exception has occurred: ' + e.getMessage());
  }   
        
    }
   
    insert teamMems;
    }
}

test:
@isTest
public class addNAM_VAMtest {
	
    static testmethod void test1(){
        ts2__Placement__c plc = new ts2__Placement__c(ts2__Client__c = '00137000008cDfrAAE');
		account acct = new account(VAM_or_NAM_Member__c = '00537000003tZkqAAE', Name = 'Northwestern Medicine');  
        jstcl__PlacementTeamMember__c ptm = new jstcl__PlacementTeamMember__c(jstcl__Placement__c = 'a211G000001NrqRQAS', jstcl__User__c = '00537000003tZkqAAE',
                                                                              jstcl__CommissionPlan__c = 'a4g370000008PGJAA2', jstcl__SplitPercent__c = 100);
        
        insert acct;
        insert ptm;
    }
}

 

I am trying to create a child record (jstcl__PlacementTeamMember__c) after the creation of the parent record (ts2__Placement__c). I am able to get all of it populated in the new child record besides the jstcl__User__c field. It seems like the "newTeamMem.ts2__Client__r.VAM_or_NAM_Member__c" portion is incorrect. This is problematic to the IF statement as well because it is being fired everytime a parent record is created when it should only fire when the criteria is met. 

trigger autoAddNAM_VAM on ts2__Placement__c (after insert) {
    List<jstcl__PlacementTeamMember__c> teamMems = new List<jstcl__PlacementTeamMember__c>();
    
    for(ts2__Placement__c newTeamMem : Trigger.New){
        if (newTeamMem.ts2__Client__r.VAM_or_NAM_Member__c != null){
            teamMems.add(new jstcl__PlacementTeamMember__c(
                	jstcl__Placement__c = newTeamMem.Id,
                	jstcl__User__c = newTeamMem.ts2__Client__r.VAM_or_NAM_Member__c,
                	jstcl__CommissionPlan__c = 'a4g370000008PGRAA2',
                	jstcl__SplitPercent__c = 100));
        }
    }
    insert teamMems;
    
}
Thank you.
Hello,

I am trying to update a custom number field on a custom object (placement) from a list of a seperate custom objects (timesheets). The following returns no errors, however when I run this through an anonymous window, it doesn't properly update the TCEndDateAudit__c on the Placement object (it turns up null). 

Here is my code so far: 
public class CamstimecardEndDateAudit{
public void auditTimeCards(){
    List<jstcl__TG_Timesheet__c> myList = new List<jstcl__TG_Timesheet__c>();

     myList = [SELECT jstcl__Placement__r.Name, Period__c, jstcl__Placement__r.TCEndDateAudit__c
                            FROM jstcl__TG_Timesheet__c 
                            WHERE jstcl__Placement__r.ts2__Status__c IN ('Active') 
                             AND jstcl__Week_Ending__c = LAST_N_DAYS:15
                             AND jstcl__Status__c = 'Pending' Limit 199];
    
    for(integer i=0 ; i < myList.size(); i++) {
        IF(myList[i].Period__c == 'Weekly Split'){
    myList[i].jstcl__Placement__r.TCEndDateAudit__c = myList[i].jstcl__Placement__r.TCEndDateAudit__c+ 0.5;}
       else{
    myList[i].jstcl__Placement__r.TCEndDateAudit__c = myList[i].jstcl__Placement__r.TCEndDateAudit__c+ 1;
    }
    }
    
  update myList;
}}

 
I am trying to update a custom number field of a list of custom objects. I keep receiving the error Error: Compile Error: Field is not writeable: jstcl__TG_Timesheet__c.Period__c at line 12 column 22. However, this varible isn't the one being written over, I'm just reading what it's value is on the if statement.

This is what I have so far:
public class CamstimecardEndDateAudit{
public static void auditTimeCards(){
    List<jstcl__TG_Timesheet__c> myList = new List<jstcl__TG_Timesheet__c>();

     myList = [SELECT jstcl__Placement__r.Name, Period__c, TCEndDateAuditB__c
                            FROM jstcl__TG_Timesheet__c 
                            WHERE jstcl__Placement__r.ts2__Status__c IN ('Active') 
                             AND jstcl__Week_Ending__c = LAST_N_DAYS:15
                             AND jstcl__Status__c = 'Pending'];
    
    for(integer i=0 ; i < myList.size(); i++) {
        if(myList[i].Period__c = 'Weekly Split'){
    myList[i].TCEndDateAuditB__c = myList[i].TCEndDateAuditB__c + 0.5;}
       else{
    myList[i].TCEndDateAuditB__c = myList[i].TCEndDateAuditB__c + 1;
    }
    }
    
  update myList;
}}

 
I am trying to return placements that occur in the query more than once and I am getting the error "Only root queries support aggregate expressions." Is there another way to count the placements than using a nested query? I know that GROUP BY is not supported in the sub-query but I'm unsure how else to go about it.

Here is what I have so far:
SELECT jstcl__Placement__r.Name,
(SELECT COUNT(Name) FROM Placements__r Group By Id COUNT(NAME) > 1)
FROM jstcl__TG_Timesheet__c WHERE jstcl__Placement__r.ts2__Status__c IN ('Active') AND jstcl__Week_Ending__c = LAST_N_DAYS:14 AND jstcl__Status__c = 'Pending'

 
I'm trying to grab the record id of a Timesheet and create a related Approval Log object through a GET request. When testing, the SOQL query is returning no results although I know that the string inserted is a valid Timesheet id

Apex Class:
@RestResource(urlMapping='/approve/*')
global with sharing class exAppClass {
  jstcl__TG_Timesheet__c ts = new jstcl__TG_Timesheet__c();
        // GET request
       @HttpGet
        global static jstcl__TG_Timesheet__c doGet() {
          RestRequest req = RestContext.request;
          String tsid = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

          System.debug(tsid);
          jstcl__TG_Timesheet__c ts = [SELECT Id, jstcl__Week_Ending__c FROM jstcl__TG_Timesheet__c WHERE Id = :tsid];
          insertLog(ts);
          return ts;
        }
        private static Express_Approval_Log__c insertLog(jstcl__TG_Timesheet__c ts){
          Express_Approval_Log__c log = new Express_Approval_Log__c();
          log.Name = 'EAL '+ts.jstcl__Week_Ending__c;
          log.Timesheet__c = ts.Id;
          insert log; 
          return log;
      }
  }

 
I have a Timesheet object and once the Timesheet status field is changed to "Submitted", it kicks off an automated workflow that sends an email to the Contact associated with the Timesheet record (Timesheet Approver). The Classic Email Template (HTML) I created, grabs the Timesheet record ID from the workflow and appends it to a Site URL that is sent in the email body. Once this link is clicked, it's supposed to take you to the Visualforce page enabled on the site and the Apex class associated with the VF page switches the Timesheet status to "Approved" when the link is clicked. Currently, once selecting the link, the URL requires a sign-in to make the update. The main goal is to be able to send an email to external contacts where they can quickly approve timesheets from clicking a link in an email and not have to login anywhere. It all works perfectly if you are signed in, but that is the main thing I'm trying to avoid. If you could help me correctly set up this Site/VF page to be visible and functional for public use, or even an entirely different way to do this, that would be greatly appreciated!
I am querying timesheets__c and looking to update the contact associated to the timesheet (timecardApprover__c) that is held in the parent object placement__c. I am able to get a list of ids of the contact I need to update but I can't figure out how to to update the field current_timesheet_status__c associated with the contact. 
public with sharing class contFlag {
    public contFlag() {

        List<String> timecardApproverIds = new List<String>();
        Set<Id> setofIds = new Set<Id>();

    for(jstcl__TG_Timesheet__c ts : [SELECT Placement__r.TimecardApprover__c FROM Timesheet__c WHERE Placement__r.Status__c = 'Active' AND Status__c = 'Pending']){
              timecardApproverIds.add(String.valueOf(ts));
        }

    for(String a : timecardApproverIds){
            setofIds.add(Id.valueOf(a));
        }
    for(Id c : setofIds){
        c.Current_Timesheet_Status__c = 'Pending';
        // returns error of variable does not exist due to it not being for the contact object
        }
    }
}


 

I am trying to pass 2 object ids to an apex controller in order to use for a SOQL query. I then want to pass the list created in the SOQL query back to the javascript controller. There, I want to see if the list is empty or not and fire a message depending on the result.

component:

<aura:component  implements="flexipage:availableForRecordHome,force:hasRecordId,flexipage:availableForAllPageTypes,force:lightningQuickAction,force:appHostable" controller="getPTM" access="global">
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="plc" type="ts2__Placement__c"/>
    <aura:attribute name="user" type="String"/>
    <aura:attribute name="plan" type="String"/>
     <aura:attribute name="cpaList" type="jstcl__TG_Commission_Plan_Assignment__c[]"/>
    <aura:attribute name="parentId" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"></aura:handler>
	<aura:handler event="c:selectedsObjectRecordsEvent" action="{!c.submitIt}" />
    <lightning:recordEditForm aura:id="editfrm" recordId="{!v.recordId}" objectApiName="jstcl__PlacementTeamMember__c" onload="{!c.onloadrec}" onsuccess="{!c.successsave}"  > 
        <div class="slds-grid slds-gutters slds-p-horizontal_small">  
            <div class="slds-p-around_xx-small slds-size_2-of-8">   <lightning:inputField aura:id="plc" fieldName="jstcl__Placement__c" value="{!v.parentId}"/></div>
            <div class="slds-p-around_xx-small slds-size_2-of-8">   <lightning:inputField aura:id="user" fieldName="jstcl__User__c" value="{!v.user}"/></div>
            <div class="slds-p-around_xx-small slds-size_2-of-8">   <lightning:inputField aura:id="plan" fieldName="jstcl__CommissionPlan__c" value="{!v.plan}"/></div>
            <div class="slds-p-around_xx-small slds-size_1-of-8">   <lightning:inputField aura:id="split" fieldName="jstcl__SplitPercent__c"/></div>
            <div class="slds-p-around_xx-small slds-size_1-of-8 slds-m-top_large">   <lightning:button variant="brand"
			iconName="utility:add" label="Add User" title="Add User" onclick="{! c.greyOut }" /></div>
        </div>
    </lightning:recordEditForm>
</aura:component>
Component Controller
doInit: function(component, event, helper) {
        //Create the action
       var action = component.get("c.plcGetCPA");
       var user = component.get("v.user");
        var plan = component.get("v.plan");
        action.setParams({
            "user" : user,
            "plan" : plan
        });
        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
               component.set("v.cpaList", response.getReturnValue());
            }
            else { console.log("Failed with state: " + state); }
        });
        // Send action off to be executed
        $A.enqueueAction(action);
    },
    greyOut : function(component , event , helper){
        var toastEvent = $A.get("e.force:showToast");
        var user = component.get("v.user");
        var plan = component.get("v.plan");
        var cpaList = component.get("v.cpaList");
		var cpaLength = cpaList.length;
        component.set("v.isOpen", !component.get("v.isOpen"));
        
        if(cpaLength > 0){
        toastEvent.setParams({
            title : 'Success',
            message:'Commission Plan matches.' + cpaList +" -------- "+ plan,
            duration:'5000',
            key: 'info_alt',
            type: 'error',
            mode: 'pester' });
        toastEvent.fire();}   
     else { toastEvent.setParams({
            title : 'Error',
            message:'Commission Plan does not match the user.' + user +' '+ plan,
            duration:'5000',
            key: 'info_alt',
            type: 'error',
            mode: 'pester' });
        toastEvent.fire();}    
    }

Apex Controller:
public class getPTM {
AuraEnabled
    public static List<jstcl__TG_Commission_Plan_Assignment__c> plcGetCPA(List<Id> userId, List<Id> planId){
       
        List<jstcl__TG_Commission_Plan_Assignment__c> cpaList= new List<jstcl__TG_Commission_Plan_Assignment__c>();
        cpaList = [SELECT Id
                   FROM jstcl__TG_Commission_Plan_Assignment__c 
                   WHERE jstcl__User__r.Id IN :userId AND jstcl__Commission_Plan__r.Id IN :planId];
       
    return cpaList;
        
    }

}

 
Hi,
I am trying to get a test class written for this trigger that adds a child record after the creation of the parent record. I am getting the following error -
"System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, jstcl.PlacementTeamMember: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.jstcl.PlacementTeamMemberTriggerHandler.validateTeamMembers: line 14, column 1
Trigger.jstcl.PlacementTeamMember: line 2, column 1: []"

trigger:
trigger autoAddNAM_VAM on ts2__Placement__c (after insert) {
    List<jstcl__PlacementTeamMember__c> teamMems = new List<jstcl__PlacementTeamMember__c>();
     Set<Id> tsClientSet = new Set<id>();
      Map<ID, Account> tsClientmap = new Map<ID, Account> ();   // Check the API Name of ts2__Client__c object
 for(ts2__Placement__c newTeamMem : Trigger.New)
    {
        
        if(newTeamMem.ts2__Client__c != null)
        {
            
            tsClientSet.add(newTeamMem.ts2__Client__c);
        }
    }
    
    if(tsClientSet.size() > 0)
    {
        tsClientmap = new Map<ID, Account>([SELECT Id, VAM_or_NAM_Member__c from Account where Id IN: tsClientSet]);
    }
    for(ts2__Placement__c newTeamMem : Trigger.New){

        if(tsClientmap.Containskey(newTeamMem.ts2__Client__C))
        {
                      
  try{ 
            if (tsClientmap.get(newTeamMem.ts2__Client__C).VAM_or_NAM_Member__c != null ){
                teamMems.add(new jstcl__PlacementTeamMember__c(
                        jstcl__Placement__c = newTeamMem.Id,
                        jstcl__User__c = tsClientmap.get(newTeamMem.ts2__Client__C).VAM_or_NAM_Member__c,
                        jstcl__CommissionPlan__c = [Select jstcl__Commission_Plan__c
                                                    FROM jstcl__TG_Commission_Plan_Assignment__c 
                                                    WHERE jstcl__Commission_Plan__r.Name LIKE '%Plan%' AND jstcl__User__c = :tsClientmap.get(newTeamMem.ts2__Client__C).VAM_or_NAM_Member__c].jstcl__Commission_Plan__c,
                        jstcl__SplitPercent__c = 100));
            }
  }catch(exception e){
       System.debug('The following exception has occurred: ' + e.getMessage());
  }   
        
    }
   
    insert teamMems;
    }
}

test:
@isTest
public class addNAM_VAMtest {
	
    static testmethod void test1(){
        ts2__Placement__c plc = new ts2__Placement__c(ts2__Client__c = '00137000008cDfrAAE');
		account acct = new account(VAM_or_NAM_Member__c = '00537000003tZkqAAE', Name = 'Northwestern Medicine');  
        jstcl__PlacementTeamMember__c ptm = new jstcl__PlacementTeamMember__c(jstcl__Placement__c = 'a211G000001NrqRQAS', jstcl__User__c = '00537000003tZkqAAE',
                                                                              jstcl__CommissionPlan__c = 'a4g370000008PGJAA2', jstcl__SplitPercent__c = 100);
        
        insert acct;
        insert ptm;
    }
}

 

I am trying to create a child record (jstcl__PlacementTeamMember__c) after the creation of the parent record (ts2__Placement__c). I am able to get all of it populated in the new child record besides the jstcl__User__c field. It seems like the "newTeamMem.ts2__Client__r.VAM_or_NAM_Member__c" portion is incorrect. This is problematic to the IF statement as well because it is being fired everytime a parent record is created when it should only fire when the criteria is met. 

trigger autoAddNAM_VAM on ts2__Placement__c (after insert) {
    List<jstcl__PlacementTeamMember__c> teamMems = new List<jstcl__PlacementTeamMember__c>();
    
    for(ts2__Placement__c newTeamMem : Trigger.New){
        if (newTeamMem.ts2__Client__r.VAM_or_NAM_Member__c != null){
            teamMems.add(new jstcl__PlacementTeamMember__c(
                	jstcl__Placement__c = newTeamMem.Id,
                	jstcl__User__c = newTeamMem.ts2__Client__r.VAM_or_NAM_Member__c,
                	jstcl__CommissionPlan__c = 'a4g370000008PGRAA2',
                	jstcl__SplitPercent__c = 100));
        }
    }
    insert teamMems;
    
}
Thank you.
Hello,

I am trying to update a custom number field on a custom object (placement) from a list of a seperate custom objects (timesheets). The following returns no errors, however when I run this through an anonymous window, it doesn't properly update the TCEndDateAudit__c on the Placement object (it turns up null). 

Here is my code so far: 
public class CamstimecardEndDateAudit{
public void auditTimeCards(){
    List<jstcl__TG_Timesheet__c> myList = new List<jstcl__TG_Timesheet__c>();

     myList = [SELECT jstcl__Placement__r.Name, Period__c, jstcl__Placement__r.TCEndDateAudit__c
                            FROM jstcl__TG_Timesheet__c 
                            WHERE jstcl__Placement__r.ts2__Status__c IN ('Active') 
                             AND jstcl__Week_Ending__c = LAST_N_DAYS:15
                             AND jstcl__Status__c = 'Pending' Limit 199];
    
    for(integer i=0 ; i < myList.size(); i++) {
        IF(myList[i].Period__c == 'Weekly Split'){
    myList[i].jstcl__Placement__r.TCEndDateAudit__c = myList[i].jstcl__Placement__r.TCEndDateAudit__c+ 0.5;}
       else{
    myList[i].jstcl__Placement__r.TCEndDateAudit__c = myList[i].jstcl__Placement__r.TCEndDateAudit__c+ 1;
    }
    }
    
  update myList;
}}

 
I currently am working on creating an Apex Class that initiially pulls a specific set of Placements (jstcl__Placement__c) and puts them in a list. 
It then takes that list of Placement Ojects and edits a relevant field called TimecardEnddateAudit__c field. I keep getting errors saying that the field jstcl__Timesheet_Period__c that exists in some of my if logic does not exist. Logically it should edit fields according to the logic:" If the jstcl__Timesheet_Period__c field is equal to 'Weekly Split' then add .5, else add 1. 
public class CamstimecardEndDateAudit{
public static void auditTimeCards(){

List<sObject> placements = [SELECT jstcl__Placement__r.Name
                            FROM jstcl__TG_Timesheet__c 
                            WHERE jstcl__Placement__r.ts2__Status__c IN ('Active') 
                             AND jstcl__Week_Ending__c = LAST_N_DAYS:15
                             AND jstcl__Status__c = 'Pending'];
                             
    for(List<sObject> A : placements){

        if(A.jstcl__Timesheet_Period__c = 'Weekly Split'){
        
        TimecardEndDateAudit__c = TimecardEndDateAudit__c + 0.5;}
        
        else{
        
        TimecardEndDateAudit__c = TimecardEndDateAudit__c ++;
}
}
}}