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
| var arr = [1,2,3,4,5]; | |
| function promiseAdd(prevPromise, val) { | |
| return prevPromise.then((sum) => sum + val); | |
| } | |
| var sum = arr.reduce(promiseAdd, Promise.resolve(0)); | |
| sum.then(console.log); |
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
| System.runAs([SELECT Id FROM User WHERE Id = :UserInfo.getUserId()][0]) { | |
| // some execution with potential mixed dml operations | |
| } |
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
| // put your target sObject API Name into the array | |
| List<String> sObjs = new List<String>{'MyObject1__c', 'MyObject2__c'}; | |
| for(String sObj : sObjs) { | |
| String soql = 'SELECT Id FROM ' + sObj; | |
| delete(Database.query(soql)); | |
| } |
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
| String username = ''; | |
| User u = [select id from user where username = :username]; | |
| u.isActive = false; | |
| Blob blobKey = Crypto.generateAesKey(256); | |
| String key = EncodingUtil.convertToHex(blobKey); | |
| u.username = key + '@junk.com'; | |
| update u; |
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
| Foo up = new Foo( | |
| userId__c = u.Id, | |
| permissions__c = '[]' | |
| ); | |
| try { | |
| insert up; | |
| throw new TestException(); // force to run catch block if insert do not throw exception | |
| } catch (Exception e) { // catch exception from insert | |
| System.Assert(e.getMessage().contains('Foo already exist!')); |
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
| List<SObject> so = new List<SObject>(); | |
| for(Lead l : leads) | |
| so.add(l); | |
| for(Contact c : contacts) | |
| so.add(c); | |
| for(Account a : accounts) | |
| so.add(a); |
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
| @future | |
| // future method does not support list of objects, so we are going to use | |
| // so tweak method in order to pass necessary info to create new PermissionSetAssignment | |
| private static void createPermissionSetAssignments(List<String> createData) { | |
| List<PermissionSetAssignment> insertPSAs = new List<PermissionSetAssignment>(); | |
| for(String data : createData) { | |
| String[] ids = data.split(';'); | |
| PermissionSetAssignment psa = new PermissionSetAssignment( |
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
| Trigger myTrigger on Contact(before insert) { | |
| map<Id,Account> accountMap = new map<Id,Account>(); | |
| for(Contact c : trigger.new){ | |
| accountMap.put(c.AccountId, null); | |
| } | |
| accountMap.remove(null); | |
| accountMap.putAll([Select Id, Name, ShippingCity From Account Where Id In : accountMap.keyset()]); | |
| for(Contact c : trigger.new){ | |
| if(accountMap.containsKey(c.AccountId)){ | |
| c.ShippingCity = accountMap.get(c.AccountId).ShippingCity; |
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
| //Your dynamic query | |
| String accountDynamicQuery = 'select id from account limit 50000' ; | |
| //Typecasting it to map | |
| Map<id,account> mapAcc = new Map<id,account>((List<account>)Database.query(accountDynamicQuery)); |
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
| String queryString = 'SELECT Id,Name FROM ABCMap__c'; | |
| if(dummyInstance.Account__c != null) | |
| queryString += ' WHERE Account__c=\'' + dummyInstance.Account__c + '\''; | |
| if(dummyMap.profileID__c != null) { | |
| if(dummyInstance.Account__c != null) | |
| queryString += ' AND '; | |
| else | |
| queryString += ' WHERE '; | |
| queryString += 'profileID__c=\'' + dummyMap.profileID__c + '\''; | |
| } |
NewerOlder