Last active
September 4, 2017 18:08
-
-
Save ChuckJonas/45fddd9fd248833d8f43fa520027ffda to your computer and use it in GitHub Desktop.
Little Heap of Horrors skill challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//replace with the id of uploaded image | |
ProductCreator.createProduct('[REPLACE]'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProductCreator { | |
//cannot modify signiture | |
@future public static void createProduct(Id attchId){ | |
Attachment attch = [SELECT Name, Body FROM Attachment WHERE ID = :attchId]; | |
String image = EncodingUtil.base64Encode(attch.Body); | |
HorrorProduct product = new HorrorProduct(attch.name, image); | |
String body = JSON.serialize(product); | |
HttpRequest req = createRequest('https://example.com/newProduct', 'POST', body); | |
sendRequest(req); | |
} | |
private static HttpRequest createRequest(String endpoint, String method, String body){ | |
HttpRequest req = new HttpRequest(); | |
req.setEndpoint(endpoint); | |
req.setBody(body); | |
req.setMethod(method); | |
return req; | |
} | |
public class HorrorProduct{ | |
public String name {get; set;} | |
public String image {get; set;} //base64 encoded string | |
public HorrorProduct(String name, String image){ | |
this.name = name; | |
this.image = image; | |
} | |
} | |
//DO NOT MODIFY ANYTHING BELOW THIS LINE. Everything above is fair game! | |
private static void sendRequest(HttpRequest req){ | |
System.assert(Limits.getHeapSize() < Limits.getLimitHeapSize(), 'Heap overallocated by ' + ((Limits.getHeapSize() - Limits.getLimitHeapSize())/1000) + ' kb'); | |
System.debug('Congratulations! You have ' + (Limits.getLimitHeapSize() - Limits.getHeapSize()) + ' bytes of heap memory remaining'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment