Skip to content

Commit

Permalink
Merge pull request #1 from tet3/tet3-edits
Browse files Browse the repository at this point in the history
spelling and grammar edits
  • Loading branch information
ChuckJonas authored Oct 10, 2019
2 parents ea0ba20 + a524263 commit 0eb3a62
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# What the f*ck Apex?
# What the f*ck, Apex?

> A list of funny and tricky Apex examples
Expand All @@ -8,14 +8,14 @@ Inspired by [wtfjs](https://github.com/denysdovhan/wtfjs)

``` apex
Boolean b;
if(b!=true) system.debug(b is not true);
if(b!=false) system.debug(b is not false);
if(b!=true) system.debug('b is not true');
if(b!=false) system.debug('b is not false');
```

See [Advanced Apex Programming in Salesforce](http://advancedapex.com/2012/08/23/funwithbooleans/) for explination.
See [Advanced Apex Programming in Salesforce](http://advancedapex.com/2012/08/23/funwithbooleans/) for explanation.


### String compare is Case-insenstive (except when it's not)
### String compare is case-insensitive (except when it's not)

``` apex
String x = 'Abc';
Expand All @@ -38,7 +38,7 @@ public class Database {
}
```

Running `Database.query('foo')` will call our new class (essentially override the [Database methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm)!?)
Running `Database.query('foo')` will call our new class (essentially override the [Database methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm))!?


[source](https://twitter.com/FishOfPrey/status/1013530412121915392)
Expand All @@ -52,7 +52,7 @@ System.assertEquals(IExist.class, IExist.IDont.Class); //passes

Source: [Kevin Jones](https://twitter.com/nawforce/status/1154135982280597504)

### Exception are "exceptional"
### Exceptions are "exceptional"

In their naming conventions:

Expand All @@ -70,18 +70,18 @@ public class BeesException extends Exception{
//fails: System exception constructor already defined: <Constructor>()
```

[For Explination see](https://www.ca-peterson.com/2015/01/23/leaky_abstractions_apex_exception_types/)
For explanation and further interesting observations, [see Chris Peterson's blog post.](https://www.ca-peterson.com/2015/01/23/leaky_abstractions_apex_exception_types/)

### System can have ambiguous returns types
### `System` can have ambiguous return types

`Database.query` is one of many cases where the salesforce "System" namespace doesn't play by it's own rules. It can either return a `List<SObject>` or a single `SObject`. No Casting required.
`Database.query` is one of many cases where the Salesforce `System` namespace doesn't play by its own rules. It can return either a `List<SObject>` or a single `SObject`. No casting required.

```java
Foo__c foo = Database.Query('SELECT Id FROM Foo__c');
List<Foo__c> foos = Database.Query('SELECT Id FROM Foo__c');
```

Try writing your own method to do this and you'll get a error:
Try writing your own method to do this and you'll get an error:

> Method already defined: query SObject Database.query(String) from the type Database (7:27)
Expand Down Expand Up @@ -123,11 +123,11 @@ String.join((Iterable<String>) mySet, ',');

[Enums in batch](https://salesforce.stackexchange.com/questions/158557/enums-as-map-keys-dont-work-in-batchable)

[Objects in hascodes](https://salesforce.stackexchange.com/questions/41741/map-set-size-when-sobjects-are-duplicated/41743#41743)
[Objects in hashcodes](https://salesforce.stackexchange.com/questions/41741/map-set-size-when-sobjects-are-duplicated/41743#41743)

### JSON Serialization

1. There way to control automatic serialization of object properties (like `[JsonProperty(PropertyName = "FooBar")]` in C#)
1. There's no way to control automatic serialization of object properties (like `[JsonProperty(PropertyName = "FooBar")]` in C#)
2. There are reserved keywords that you can't use as property names.

Meaning the following cannot be parsed or generated using `JSON.deserialize` or `JSON.serialize`:
Expand All @@ -139,13 +139,13 @@ Meaning the following cannot be parsed or generated using `JSON.deserialize` or
}
```

[Work Around](https://salesforce.stackexchange.com/questions/2276/how-do-you-deserialize-json-properties-that-are-reserved-words-in-apex)
[Work-around](https://salesforce.stackexchange.com/questions/2276/how-do-you-deserialize-json-properties-that-are-reserved-words-in-apex)

### Generics (parametrized interfaces) exist but you can't use them
### Generics (parameterized interfaces) exist, but you can't use them

Apperently once upon a time, generics were part of apex. However, they have since been removed (with the exception of system classes (`List<>`, `Batchable<>`, etc).
Apparently, once upon a time, generics were part of Apex. However, they have since been removed (with the exception of system classes (`List<>`, `Batchable<>`, etc).

Why would you want generics when you're OS has perfectly good Copy & Paste functionality built right into it?
Why would you want generics when your OS has perfectly good Copy & Paste functionality built right into it?

[Vote for Generics](https://success.salesforce.com/ideaView?id=08730000000aDnYAAU)

Expand All @@ -172,17 +172,18 @@ System.debug(x instanceOf Double); // true
System.debug(x instanceOf Decimal); // true
```

Source [Dainel Barrileger](https://twitter.com/FishOfPrey/status/1051965154454265856)
Source [Daniel Ballinger](https://twitter.com/FishOfPrey/status/1051965154454265856)


## Since Fixed

Thankfully these WTF's have since been fixed by Salesforce. We'll keep them documented for historical purposes (and entertainment).
Thankfully these WTFs have since been fixed by Salesforce. We'll keep them documented for historical purposes (and entertainment).

### Mutating Dates
### Mutating Datetimes

https://twitter.com/FishOfPrey/status/869381316105588736

### More hashcode fun
https://twitter.com/FishOfPrey/status/1016821563675459585

https://salesforce.stackexchange.com/questions/224490/bug-in-list-contains-for-id-data-type

0 comments on commit 0eb3a62

Please sign in to comment.