Suppose we would like to read static data we would prefer Custom Settings.
What if we have a data more than 255 characters. We can read it from Document as below.
/**
* @description Document helper.
*/
public class DocumentHelper {
private static List<Document> documentList;
/**
* @name getQueryDocument
* @description Get Query from Document by Name.
* @param docName Document Name
* @return String
*/
public static String getQueryFromDocument(String docName) {
getQueryDocumentList();
for (Document document : documentList) {
if (document.Name == docName) {
return document.Body.toString();
}
}
return '';
}
/**
* @name getQueryDocumentList
* @description Get Documents form Queries Folder.
* @return void
*/
private static void getQueryDocumentList() {
if (documentList == null) {
documentList = [
SELECT Name, Body
FROM Document
WHERE Folder.Name = 'Queries'];
}
}
}
What if we have a data more than 255 characters. We can read it from Document as below.
/**
* @description Document helper.
*/
public class DocumentHelper {
private static List<Document> documentList;
/**
* @name getQueryDocument
* @description Get Query from Document by Name.
* @param docName Document Name
* @return String
*/
public static String getQueryFromDocument(String docName) {
getQueryDocumentList();
for (Document document : documentList) {
if (document.Name == docName) {
return document.Body.toString();
}
}
return '';
}
/**
* @name getQueryDocumentList
* @description Get Documents form Queries Folder.
* @return void
*/
private static void getQueryDocumentList() {
if (documentList == null) {
documentList = [
SELECT Name, Body
FROM Document
WHERE Folder.Name = 'Queries'];
}
}
}