Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added section documenting Special File Meta Object Usage for beforeSave and onSave

...

Code Block
DEFAULT{
Action=SetVar;
VarName=Order_Id;
VarValue=Order__c;
|
Action=SqlQuery;
QueryString=Select SUM ( CAST( Amount__c AS REAL ) ) AS SUM_ORDER_AMOUNT FROM Order_Line_Item__c WHERE Order__c = ‘%%Order_Id%%’;
QueryReturnFields=SUM_ORDER_AMOUNT;
|
Action=SqlQuery;
QueryString=Update Order__c SET Sub_Total__c = ‘%%SUM_ORDER_AMOUNT%%’ WHERE Id = ‘%%Order_Id%%’;
}

Special File Meta Object Usage for beforeSave and onSave

There is a special "FILE" meta object concept available as of Pulsar 9.0. It encapsulates and makes available data on all 3 content objects (ContentDocument, ContentVersion, and ContentDocumentLink),  within a single PSL beforeSave Validation Rule or PSL onSave Trigger, when saving files or attachments on other objects. For example, you could define a pulsar.beforeSave.File validation rule to restrict file types being added to Account Related Files.


The Full list of data available in pulsar.beforeSave.File or pulsar.onSave.File PSL follows:

ContentDocumentContentVersionContentDocumentLink

ContentDocument_Id

ContentVersion_IdContentDocumentLink_ContentDocumentIdorContentDocumentId
ContentDocument_FileExtensionContentVersion_ContentDocumentIdContentDocumentLink_LinkedEntityIdorLinkedEntityId
ContentDocument_FileMimeTypeContentVersion_FileExtensionContentDocumentLink_SystemModstamporSystemModstamp
ContentDocument_ContentSizeContentVersion_FileMimeTypeContentDocumentLink_ShareTypeorShareType
ContentDocument_ContentSizeMBContentVersion_ContentSizeContentDocumentLink_VisibilityorVisibility
ContentDocument_Base64ContentSizeContentVersion_ContentSizeMB


ContentDocument_Base64ContentSizeMBContentVersion_Base64ContentSize


ContentDocument_TitleContentVersion_Base64ContentSizeMB


ContentDocument_DescriptionContentVersion_Title



ContentVersion_Description



ContentVersion_Origin



ContentVersion_PathOnClient



Example of data available in PSL:

DatumExample ValueNotes
ContentDocument_Id0695e000007oQsJAAUwill be empty in beforeSave
ContentDocument_FileExtensionmp4
ContentDocument_FileMimeTypevideo/mp4
ContentDocument_ContentSize12207543
ContentDocument_ContentSizeMB11.64
ContentDocument_Base64ContentSize16236032
ContentDocument_Base64ContentSizeMB15.48
ContentDocument_Titleexample.mp4
ContentDocument_DescriptionExample MP4 Video
ContentVersion_Id0685e000007xDBQAA2will be empty in beforeSave
ContentVersion_ContentDocumentId0695e000007oQsJAAUwill be empty in beforeSave
ContentVersion_FileExtensionmp4
ContentVersion_FileMimeTypevideo/mp4
ContentVersion_ContentSize12207543
ContentVersion_ContentSizeMB11.64
ContentVersion_Base64ContentSize16236032
ContentVersion_Base64ContentSizeMB15.48
ContentVersion_Titleexample.mp4
ContentVersion_DescriptionExample MP4 Video
ContentVersion_OriginC
ContentVersion_PathOnClientexample.mp4
ContentDocumentLink_ContentDocumentId0695e000007oQsJAAUwill be empty in beforeSave
ContentDocumentLink_LinkedEntityId0016A00000oCv1dQAC
ContentDocumentLink_SystemModstamp2022-05-18T16:27:20.149+0000
ContentDocumentLink_ShareTypeV
ContentDocumentLink_VisibilityAllUsers

Example pulsar.beforeSave.File

The pulsar.beforeSave.File validation rule can be used to prevent an end user from saving files based on custom logic. The example below restricts by file extension as well as size of the file.

Code Block
DEFAULT {
Action=SetVar;
VarName=MaxFileSizeBytes;
VarValue=1000000;
|
Action=SetVar;
VarName=FileSizeBase64;
VarValue=ContentVersion_Base64ContentSize;
|
Action=SetVar;
VarName=Extension;
VarValue=ContentVersion_FileExtension;
|
Action=Log;
Message=FileSizeBase64 [%%FileSizeBase64%%] Extension [%%Extension%%];
|
Action=__CHECKFEXT;
|
Action=__CHECKSIZE;
}
CHECKSIZE {
Action=SqlQuery;
QueryString=SELECT %%FileSizeBase64%% AS TheValue;
QueryReturnFields=TheValue;
QueryTest=%%TheValue%% > %%MaxFileSizeBytes%%;
QueryTestTrue=CANTUPLOAD;
}
CHECKFEXT {
Action=SqlQuery;
QueryString=Select (CASE WHEN UPPER('%%Extension%%') IN ('ZIP','TXT','EXE','PY','PHP','ASP','ASPX','JAR','BAT','BIN','MSI','REG','VB','VBS','WS','SCR','PL','JSP') THEN 1 ELSE 0 END) as ValidateFileTypeCheck;
QueryReturnFields=ValidateFileTypeCheck;
QueryTest=%%ValidateFileTypeCheck%%=1;
QueryTestTrue=BAD_FILE_EXTENSION;
}
BAD_FILE_EXTENSION{
Action=SetResult;
Result=Invalid File Type;
ResultValid=false;
}
CANTUPLOAD{
Action=SetResult;
Result=Max file size is 1 mb.;
ResultValid=false;
}

Example pulsar.onSave.File

The pulsar.onSave.File trigger can be used to perform custom logic after a file has been saved. The below example outputs some basic information to the log upon saving an Attachment or File on an object such as an Account or Contact object.

Code Block
DEFAULT{
Action=SetVar;
VarName=ParentObjectId;
VarValue=LinkedEntityId;
|
Action=SetVar;
VarName=Extension;
VarValue=ContentVersion_FileExtension;
|
Action=SetVar;
VarName=ContentSizeMB;
VarValue=ContentVersion_ContentSizeMB;
|
Action=SetVar;
VarName=Base64ContentSizeMB;
VarValue=ContentVersion_Base64ContentSizeMB;
|
Action=SetVar;
VarName=ContentTitle;
VarValue=ContentVersion_Title;
|
Action=SetVar;
VarName=ContentDescription;
VarValue=ContentVersion_Description;
|
Action=Log;
Message="EXAMPLE: ParentObjectId: %%ParentObjectId%%, FileExt (%%Extension%%), SizeMB (%%ContentSizeMB%% , %%Base64ContentSizeMB%%), Title (%%ContentTitle%%), Description (%%ContentDescription%%)";
|
Action=GetObjectType;
ObjectId=%%ParentObjectId%%;
VarName=ParentObjectType;
|
Action=Log;
Message="EXAMPLE: ParentObjectType: %%ParentObjectType%%";
}

Field Triggers

Currently we only support the 'After Update' trigger type for reference fields only.  The trigger code can be any valid PSL and is executed only after a specified reference field has been updated.

...