Last active
October 17, 2018 20:47
-
-
Save SalesforceBobLightning/55f26482b1a91191096f1368bd5970e4 to your computer and use it in GitHub Desktop.
Custom Logging using Apex
This file contains hidden or 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 without sharing class CustomLog { | |
| private static StringBuffer buffer; | |
| static { | |
| buffer = new StringBuffer(); | |
| } | |
| public static void append(String value) { | |
| buffer.append(value + '\n'); | |
| } | |
| public static String toStr() { | |
| return buffer.toStr(); | |
| } | |
| public static void attach(Id recordId) { | |
| ContentVersion contentVersion = new ContentVersion( | |
| versionData = Blob.valueOf(buffer.toStr()), | |
| title = 'Custom Log', | |
| pathOnClient = '/Custom-Log-' + DateTime.now().getTime() + '.txt', | |
| FirstPublishLocationId = recordId); | |
| insert contentVersion; | |
| } | |
| public static void attachToCurrentUser() { | |
| attach(UserInfo.getUserId()); | |
| } | |
| } |
This file contains hidden or 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
| /* ============================================================ | |
| * This code is part of the "apex-lang" open source project avaiable at: | |
| * | |
| * http://code.google.com/p/apex-lang/ | |
| * | |
| * This code is licensed under the Apache License, Version 2.0. You may obtain a | |
| * copy of the License at: | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * ============================================================ | |
| */ | |
| global class StringBuffer { | |
| private String theString; | |
| global StringBuffer(){ | |
| this(''); | |
| } | |
| global StringBuffer(String str){ | |
| theString = str; | |
| } | |
| global StringBuffer(Decimal d){ | |
| theString = '' + d; | |
| } | |
| global StringBuffer(Double d){ | |
| theString = '' + d; | |
| } | |
| global StringBuffer(Long l){ | |
| theString = '' + l; | |
| } | |
| global StringBuffer(Integer i){ | |
| theString = '' + i; | |
| } | |
| global StringBuffer(Blob b){ | |
| theString = '' + b; | |
| } | |
| global StringBuffer(Boolean b){ | |
| theString = '' + b; | |
| } | |
| global StringBuffer(Date d){ | |
| theString = '' + d; | |
| } | |
| global StringBuffer(Datetime d){ | |
| theString = '' + d; | |
| } | |
| global StringBuffer(ID id){ | |
| theString = '' + id; | |
| } | |
| global StringBuffer(Time t){ | |
| theString = '' + t; | |
| } | |
| global StringBuffer append(String str){ | |
| theString += str; return this; | |
| } | |
| global StringBuffer append(Decimal d){ | |
| theString += d; return this; | |
| } | |
| global StringBuffer append(Double d){ | |
| theString += d; return this; | |
| } | |
| global StringBuffer append(Long l){ | |
| theString += l; return this; | |
| } | |
| global StringBuffer append(Integer i){ | |
| theString += i; return this; | |
| } | |
| global StringBuffer append(Blob b){ | |
| theString += b; return this; | |
| } | |
| global StringBuffer append(Boolean b){ | |
| theString += b; return this; | |
| } | |
| global StringBuffer append(Date d){ | |
| theString += d; return this; | |
| } | |
| global StringBuffer append(Datetime d){ | |
| theString += d; return this; | |
| } | |
| global StringBuffer append(ID id){ | |
| theString += id; return this; | |
| } | |
| global StringBuffer append(Time t){ | |
| theString += t; return this; | |
| } | |
| global String toStr(){ | |
| return theString; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment