Skip to content

Instantly share code, notes, and snippets.

@jason-den
jason-den / GetRequiredFields.apex
Last active July 8, 2021 23:26
Get required fields from a given object. Code is supposed to execute as anonymous code in SF developer console
string objectName = 'Assessment__c'; // Usage: change the object name here
Map<String, Schema.SObjectType> gdesc = Schema.getGlobalDescribe();
Sobject objectt = gdesc.get(objectName).newSObject();
Schema.DescribeSObjectResult r = objectt.getSObjectType().getDescribe();
Map<String,Schema.SObjectField> M = r.fields.getMap();
for(String fieldName : M.keySet()) {
Schema.SObjectField field = M.get(fieldName);
Schema.DescribeFieldResult F = field.getDescribe();
Boolean isFieldreq = F.isCreateable() && !F.isNillable() && !F.isDefaultedOnCreate();
if (isFieldreq) {
// Reference - https://mongoosejs.com/docs/transactions.html
// "mongoose": "^5.11.2"
const assert = require("assert")
const mongoose = require("mongoose")
const case1 = () => {
// Expect Output:
// >>> case 1 catch error error.message
// >>> case1 finally
@jason-den
jason-den / how_are_you_comps.js
Created September 3, 2020 10:38
Script to scrap company stock price from ASX.
/*
We want to know how are the companies doing during VOVID19 simply look at their stock price.
- scope: ASX companies. AKA comp_list. Based on a ASX official list.
1. get the comp_list
2. get the price data by requesting yahoo API
for comp in comp_list:
2.1 get the before_COVID_price
2.2 get the current_price
3. get the price_change_percentage by compare result of 1&2
# hello world
> A testing blog writen by gist.github.com
const obj1 = {a:'a', b:'b'}
const obj2 = {...obj1, a:'new a'}
console.log(obj2);
// > Object { a: "new a", b: "b" }
@jason-den
jason-den / mongodb_connection.js
Created February 20, 2020 10:34
mongodb connection
mongoose
.connect("mongodb://localhost/dbname")
.then(() => console.log("Connected to MongoDB"))
.catch(err => console.log(`Fail to connect to MongoDB: ${err}`));