Context Around this Code: I am making a schedulable class run each Sunday to track a couple of metrics important to the team.
Question: I am looking to consolidate DML operations and a big part of this is understanding pass by reference vs pass by value.
I want to pass the salesOps user object to the method SDREfficiencyLastWeek. I made the return type void, because I figured that I will be passing this by reference and I can make all the updates in the method without having to anything.
Why I am confused:
https://developer.salesforce.com/blogs/developer-relations/2012/05/passing-parameters-by-reference-and-by-value-in-apex.html I read the above article and am thrown off by the following statement:
"Non-primitive data type arguments, such as sObjects, are also passed into methods by value. "
If the object is indeed passed by reference, then the query for the salesOps user in my code should be sufficient enough to edit all fields on that object without actually having to state each field in the query.
global class SDREfficientMetricsSchedulable implements Schedulable
{
global void execute(SchedulableContext sc)
{
User salesOps = [SELECT ID FROM USER WHERE id = '0056A000002Z3p9QAC'];
List<String> queries = new List<String>();
String contactsWorked_lastWeek = 'select count(id) results from contact where LastActivityDate = last_week';
queries.add(contactsWorked_lastWeek);
String demosSet_lastWeek = 'select count(id) results from form__c where CreatedDate = last_week';
queries.add(demosSet_lastWeek);
String demosCompleted_lastWeek = 'select count(id) results from opportunity where (stagename = \'Unqualified Demo Completed\' OR stagename = \'Qualified Demo Completed\' ) and RecordTypeId = \'0126A000000yudDQAQ\' and CloseDate = last_week';
queries.add(demosCompleted_lastWeek);
String qualifiedDemos_lastWeek = 'select count(id) results from opportunity where RecordTypeId = \'0126A0000004Ao6QAE\' and isclosed = false and SDR_Owner__c != null and CreatedDate = last_week';
queries.add(qualifiedDemos_lastWeek);
String closedWon_lastWeek = 'select count(id) results from opportunity where RecordTypeId = \'0126A0000004Ao6QAE\' and iswon = true and SDR_Owner__c != null and CloseDate = last_week';
queries.add(qualifiedDemos_lastWeek);
SDREfficiencyLastWeek(queries, salesOps);
update salesOps;
}
public void SDREfficiencyLastWeek(List<String> queries, User salesOps )
{
}
}