Monday, 29 April 2019

Salesforce - ContentDocumentLink in test class

Account acct = new Account(Name='TEST_ACCT');
insert acct;

ContentVersion contentVersion = new ContentVersion(
  Title = 'Penguins',
  PathOnClient = 'Penguins.jpg',
  VersionData = Blob.valueOf('Test Content'),
  IsMajorVersion = true
);
insert contentVersion;    
List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

//create ContentDocumentLink  record 
ContentDocumentLink cdl = New ContentDocumentLink();
cdl.LinkedEntityId = acct.id;
cdl.ContentDocumentId = documents[0].Id;
cdl.shareType = 'V';
insert cdl;

Salesforce - Close Quick Action




$A.get("e.force:closeQuickAction").fire();





example:

({
    accept : function(component, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }
})

Monday, 1 April 2019

Mysql trigger to auto generate 18 digit Id String on before insert table record






CREATE TRIGGER `AutoGenerateIdOnTestTaker` BEFORE INSERT ON `TestTaker`
 FOR EACH ROW SET New.Id = (SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 18))