You need to sign in to do that
Don't have an account?
Luke Higgins 23
Updating a field on a custom object
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:
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; }}
It might we worthwhile to check a couple of things to verify the reason for the query not retrieving the desired result set.
- Check if the records satisfying the stated Where Clause in your SOQL actually exist on your org.
- Run the query through the SOQL Editor in Dev Console or using Workbench to check the results returned and verify if they are the expected ones.
- Check if the Users have access to those records by running the same Soql query through multiple User accounts to verify the results returned.
Also, I am curious to know if you have this class created in your Salesforce org and are just calling it through the dev console or do you have the above script written within the Execute Anonymous window of the Dev Console? If you already have the class written under Apex Classes within your org it might be worthwhile to call the same using the below code rather than rewriting it.Also try updating the Soql query to use an '=' operator with Active status rather than using the IN operator as follows.
All Answers
Thanks for the reply! This helped a ton. However when I hit 'Execute' in the Execute Anonymous Window, it doesn't seem to run the query at all and the records come up unchanged. Am I missing something?
It might we worthwhile to check a couple of things to verify the reason for the query not retrieving the desired result set.
- Check if the records satisfying the stated Where Clause in your SOQL actually exist on your org.
- Run the query through the SOQL Editor in Dev Console or using Workbench to check the results returned and verify if they are the expected ones.
- Check if the Users have access to those records by running the same Soql query through multiple User accounts to verify the results returned.
Also, I am curious to know if you have this class created in your Salesforce org and are just calling it through the dev console or do you have the above script written within the Execute Anonymous window of the Dev Console? If you already have the class written under Apex Classes within your org it might be worthwhile to call the same using the below code rather than rewriting it.Also try updating the Soql query to use an '=' operator with Active status rather than using the IN operator as follows.