Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dschach committed Oct 28, 2023
1 parent 7509d17 commit 42e0404
Show file tree
Hide file tree
Showing 4 changed files with 473 additions and 606 deletions.
189 changes: 34 additions & 155 deletions demo/testcode.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@

<body class="hljs">
<pre><code class="language-apex">
List&lt;SObject&gt; mylist = [SELECT Name, StreetAddress__c, COUNT(),
(SELECT Id FROM Contacts)
FROM Warehouse__c.Contacts__r
WHERE DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'mi') < 20
AND Date__kav NOT IN LAST_N_DAYS:80
ORDER BY DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'mi')
LIMIT 10];


delete myAccount;
Account a;
Expand All @@ -42,30 +36,30 @@

List&lt;Opportunity&gt; opps = [SELECT Id FROM Opportunity WHERE Id NOT IN :newRecordsMap.keySet()];

String queryText = 'SELECT Id, Name, AccountId, FirstName, LastName, mailingstreet, mailingcity, mailingstate, mailingpostalcode, mailingcountry, ' +
'otherstreet, othercity, otherstate, otherpostalcode, othercountry, mailinglatitude, mailinglongitude, otherlatitude, otherlongitude ' +
'FROM Contact WHERE AccountId = :acctid ORDER BY ' +
String.escapeSingleQuotes(SortFullExp) +
' NULLS LAST LIMIT 1000';
String queryText = 'SELECT Id, Name, AccountId, FirstName, LastName, mailingstreet, mailingcity, mailingstate, mailingpostalcode, mailingcountry, '

String queryText = 'SELECT Id, Name, ';
acctid = System.currentPageReference().getParameters().get('Id');
System.assert(true);
System.requestVersion();
</code></pre>
<p>-------NEW LANGUAGE----------</p>
<p>-------NEW_CODEBLOCK----------</p>
<pre><code class="language-apex">
@IsTest
private without sharing class myTestClass {
myMap?.get('Id');
}
System.URL.getCurrentRequestUrl();
System.getCurrentRequestUrl();
URL.getCurrentRequestUrl();

public List&lt;SelectOption&gt; recordTypes { get; private set; }
</code></pre>
<p>-------NEW LANGUAGE----------</p>
<p>-------NEW_CODEBLOCK----------</p>
<pre><code class="language-apex">

Database.insert(myAccounts, false, AccessLevel.USER_MODE);
delete myAccount;
delete [SELECT Id FROM Account];
myAcct = (Account)myacct;

public String myString { get; set; }

Expand All @@ -78,6 +72,19 @@
@throws DMLException
*/

List&lt;SObject&gt; mylist = [SELECT Name, StreetAddress__c, COUNT(),
(SELECT Id FROM Contacts)
FROM Warehouse__c.Contacts__r
WHERE DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'mi') < 20
AND Date__kav NOT IN LAST_N_DAYS:80
ORDER BY DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'mi')
LIMIT 10];

String queryText = 'SELECT Id, Name, AccountId, FirstName, LastName, mailingcountry, ' +
'FROM Contact WHERE AccountId = :acctid ORDER BY ' +
String.escapeSingleQuotes(SortFullExp) +
' NULLS LAST LIMIT 1000';

/**
* @author {@link [David Schach](https://github.com/dschach)}
* @group Visualforce
Expand All @@ -87,10 +94,6 @@

public enum Season {WINTER, SPRING, SUMMER, FALL}

/**
* Extension Constructor
* @param stdController `ActionPlan__c` Standard Controller
*/
public ActionPlanDetailController(ApexPages.StandardController stdController, Integer x, Double y) {
Map&ltId, Map&ltString, Wrapper&gt&gt renew = new Map&ltId, Map&ltString, SObject&gt&gt();
if (!Test.isRunningTest() && false) {
Expand All @@ -100,18 +103,15 @@
actionPlan = (ActionPlan__c) stdController.getRecord();
truestory = req.setHeader('X-Password', '{!$Credential.Password}');
}

/**
* Action on page load to ensure custom setting is created
* @return `PageReference` null (required for page actions method)
*/

public PageReference onLoad() {
ActionPlansUtilities.onPageLoad();
return null;
}

/**
* Deletes the current Action Plan loaded and redirects to the AP List
* @return `PageReference` null (required for page actions method)
* @return `PageReference` Page to go to after deleting `ActionPlan__c`
*/
public PageReference deletePlan() {
Expand Down Expand Up @@ -234,24 +234,6 @@
return false;
}

/**
* The label of the Action Plan's parent record SObject
* @return `String` Label of the object related to this Action Plan
*/
public String getRelatedObjectLabel() {
String objLabel = '';

for (String f : ActionPlansUtilities.getCustomRelationshipFields()) {
if (actionPlan.get(f) != null) {
Id objId = (Id) actionPlan.get(f);
Schema.DescribeSObjectResult dsr = objId.getSObjectType().getDescribe();
objLabel = dsr.getLabel();
break;
}
}
return objLabel;
}

/**
* The name of the parent record - show a different field based on SObject Type
* @return `String` name of the object related to this Action Plan
Expand Down Expand Up @@ -286,21 +268,6 @@
}
}

/**
* Convert AP Task Record Type Id to Record Type Name
* @return Record Type Name
*/
public String getRecordTypeName() {
String toReturn = '';
if (ActionPlansUtilities.taskUsesRecordTypes) {
Map&lt;Id, Schema.RecordTypeInfo&gt; rtMapById = Task.SObjectType.getDescribe().getRecordTypeInfosById();
if (!rtMapById.isEmpty() && rtMapById.containsKey(actionPlan.TaskRecordTypeID__c)) {
return rtMapById.get(actionPlan.TaskRecordTypeID__c).getName();
}
}
return toReturn;
}

/**
* If we have no share object, we don't need to show a Share button
* @author {@link [David Schach](https://github.com/dschach)}
Expand All @@ -309,16 +276,6 @@
public Boolean getCanShare() {
return ActionPlansUtilities.canShareRecord(actionPlan.Id, actionPlan.OwnerId);
}

/**
* Does the user have permission to transfer? We query `UserRecordAccess` to find out.
* @author {@link [David Schach](https://github.com/dschach)}
* @return `Boolean` yes/no
*/
public Boolean getCanTransfer() {
return ActionPlansUtilities.getCanTransfer(actionPlan.Id);
}
}

@SuppressWarnings('PMD.AvoidGlobalModifier')
/**
Expand All @@ -343,23 +300,10 @@
SELECT
Id,
Description__c,
Name,
OwnerId,
SkipDay__c,
SkipWeekends__c,
TaskRecordTypeID__c,
(
SELECT
Type__c,
Name,
User__c,
User__r.Name,
Id,
DaysFromStart__c,
Action_Plan_Template__c,
TController__r.Subject__c,
Minutes_Reminder__c,
TaskIndex__c,
Action_Plan_Template__r.TaskRecordTypeID__c
FROM aptTasks__r
ORDER BY TaskIndex__c ASC
Expand All @@ -376,19 +320,12 @@
templateNameOrIdToTemplate.put(apt.Id, apt);
}

Set&lt;Id&gt; relatedIDs = new Set&lt;Id&gt;();

for (CreateActionPlanRequest r : requests) {
relatedIDs.add(r.relatedRecordID);
}

Map&lt;Id, ActionPlan__c&gt; actionPlansToInsert = new Map&lt;Id, ActionPlan__c&gt;();


if (actionPlansToInsert.isEmpty()) {
return resultIDs;
}

insert actionPlansToInsert.values();

Map&lt;String, APTask__c&gt; planTaskIndexToTask = new Map&lt;String, APTask__c&gt;();
Expand All @@ -400,56 +337,25 @@

ActionPlan__c ap = actionPlansToInsert.get(r.relatedRecordID);

ActionPlanTemplate__c actionPlanTemplate = templateNameOrIdToTemplate.get(r.templateNameOrID);

for (APTemplateTask__c aptTask : actionPlanTemplate.aptTasks__r) {
APTask__c apTask = new APTask__c();
apTask.User__c = ActionPlansBuilderUtilities.getAPTaskTemplateUser(ap, relObjectOwners, aptTask.User__c);
apTask.DaysFromStart__c = aptTask.DaysFromStart__c;
apTask.Comments__c = aptTask.Comments__c;
apTask.Minutes_Reminder__c = aptTask.Minutes_Reminder__c;
apTask.SendEmail__c = aptTask.SendEmail__c;

apTask.Action_Plan__c = ap.Id;

apTask.Status__c = ActionPlansUtilities.getTaskRecordTypeStatusDefaultValues().get(ActionPlansUtilities.getDefaultTaskRecordTypeId());

if (apTask.Dependent__c != null && apTask.Dependent__c != 'None') {
apTask.ActivityDate__c = null;
// create due date, calculate the due date of the tasks for skip weekends feature
if (ap.SkipWeekends__c == true && ap.SkipDay__c != null) {
apTask.ActivityDate__c = ActionPlansUtilities.adjustTaskDueDate(ap.StartDate__c, apTask.DaysFromStart__c.intValue(), ap.SkipDay__c);
} else {
apTask.Controller__c = null;

//set dependency taskId to none if none was selected
if (apTask.Dependent__c == null) {
apTask.Dependent__c = 'None';
}

// create due date, calculate the due date of the tasks for skip weekends feature
if (ap.SkipWeekends__c == true && ap.SkipDay__c != null) {
apTask.ActivityDate__c = ActionPlansUtilities.adjustTaskDueDate(ap.StartDate__c, apTask.DaysFromStart__c.intValue(), ap.SkipDay__c);
} else {
apTask.ActivityDate__c = ap.StartDate__c.addDays(apTask.DaysFromStart__c.intValue());
}
apTask.ActivityDate__c = ap.StartDate__c.addDays(apTask.DaysFromStart__c.intValue());
}
planTaskIndexToTask.put(ap.Id + '' + apTask.TaskIndex__c, apTask);
}
}

Database.insert(new planTaskIndexToTask.values());

// Now we have to update with the controlling/dependent task IDs

List&lt;APTask__c&gt; dependentTasksToUpdate = new List&lt;APTask__c&gt;();

for (APTask__c apTask : planTaskIndexToTask.values()) {
String actionPlanPlusIndex = apTask.Action_Plan__c + '' + apTask.Dependent__c;

if (planTaskIndexToTask.containsKey(actionPlanPlusIndex)) {
apTask.Controller__c = planTaskIndexToTask.get(actionPlanPlusIndex).Id;
dependentTasksToUpdate.add(apTask);
}
}

Database.update(dependentTasksToUpdate);

List&lt;Task&gt; myTasksWithOutEmail = new List&lt;Task&gt;();
Expand All @@ -468,8 +374,6 @@
ActionPlan__c insertedAP;
// check if task exists already
Task t = new Task();
t.Subject = apTask.Subject__c;
t.Priority = apTask.Priority__c;
t.OwnerId = apTask.User__c;
t.TaskAPTask__c = apTask.Id;

Expand Down Expand Up @@ -497,35 +401,17 @@
String f = s;
if (
!f.equalsIgnoreCase(ActionPlansUtilities.namespacePrefix + 'Contact__c') &&
!f.equalsIgnoreCase(ActionPlansUtilities.namespacePrefix + 'Lead__c') &&
insertedAP.get(f) != null
) {
t.WhatId = (Id) insertedAP.get(f);
break;
}
}

if (t.Id == null) {
t.Status = apTask.Status__c;
}
t.ActivityDate = apTask.ActivityDate__c;

if (apTask.Dependent__c == 'None') {
if (apTask.SendEmail__c == true) {
myNewTasksWithEmail.add(t);
} else {
myTasksWithOutEmail.add(t);
}
}
}

Database.DMLOptions dmlo1 = new Database.DMLOptions();
dmlo1.EmailHeader.triggerUserEmail = true;

if (myTasksWithOutEmail.size() &gt; 0) {
Database.insert(myTasksWithOutEmail, dmlo2);
}

Set&lt;Id&gt; relObjectIDs = new Set&lt;Id&gt;();
for (ActionPlan__c ap : actionPlansToInsert.values()) {
relObjectIDs.add(ap.Id);
Expand Down Expand Up @@ -562,7 +448,7 @@

}
</code></pre>
<p>-------NEW LANGUAGE----------</p>
<p>-------NEW_CODEBLOCK----------</p>
<pre><code class="language-apex">
/**
* SHOULD BE RECOGNIZED AS JAVA
Expand All @@ -583,13 +469,11 @@
}

</code></pre>
<p>-------NEW LANGUAGE----------</p>
<p>-------NEW_CODEBLOCK----------</p>
<pre><code class="">
public without sharing class AccountSampleTriggerHandler extends Database.schedulable, TriggerHandler, Database.Batchable&lt;SObject&gt; {
private List&lt;Account&gt; newRecords;
private List&lt;Account&gt; oldRecords;
private Map&lt;Id, Account&gt; newRecordsMap;
private Map&lt;Id, Account&gt; oldRecordsMap;

switch on context {
when 'BEFORE_INSERT' {
Expand All @@ -611,20 +495,18 @@
*/
public AccountSampleTriggerHandler(CustomType a, String className) {
this.newRecords = (List&lt;Account&gt;) Trigger.new;
this.oldRecords = (List&lt;Account&gt;) Trigger.old;
this.newRecordsMap = (Map&lt;Id, Account&gt;) Trigger.newMap;
this.oldRecordsMap = (Map&lt;Id, Account&gt;) Trigger.oldMap;
}

public override sobject beforeInsert() {
public override sobject beforeInsert(String a, APTask__c b, DateTime c) {
method1();
}

//public override void afterUpdate(){}

private void method1() {
for (Account a : newRecords) {
a.Name = a.Name.toUpperCase();
a.Name = a.Name.toUpperCase(a, b, c);
a.Name = new FooBar();
}
}
Expand All @@ -649,9 +531,7 @@
}
}

public without sharing class AccountSampleTriggerHandler extends Database.schedulable, Batchable&lt;SObject&gt; {

}
public without sharing class AccountSampleTriggerHandler extends Database.schedulable, Batchable&lt;SObject&gt; {}

public virtual class Marker {
public virtual void write() {
Expand Down Expand Up @@ -713,7 +593,6 @@
upsert myRecord__c;
Database.upsert(myRecord__c, false, AccessLevel.USER_MODE);
}

</code></pre>
</body>
</html>
Loading

0 comments on commit 42e0404

Please sign in to comment.