Overview
Some admins have setup custom buttons backed by Apex code to accommodate a Salesforce work flow. For example, a custom button click would create an object with certain fields already filled in from the values found in the current object. Pulsar also supports defining custom buttons using Pulsar Settings and the Pulsar Settings Language (PSL).
Here are some of the actions supported within PSL that can be used for custom button actions:
Alert: Will show a pop-up dialogue with the appropriate message for the user.
Display: Another Salesforce object.
Create: Create a new object of type you specify.
CreateAndMapFields: Create a new object with fields already populated from the current object.
SetField: Set a particular field within the current object.
SetLocation: Set a particular Geolocation field within the current object.
CloneRecentObject: Create and clone the data from the most recent object in the list.
CloneCurrentObject: Create and clone the current object.
See the documentation for PSL for more detailed information.
Usage
There are two Pulsar Settings used to enable custom buttons. The format of each is below:
- Define the labels and identifiers for each custom button action.
Here is a great example of how to set up custom buttons:
First, List all the buttons that should be displayed on the Event Layout.
Name: Event custom buttons
Key: pulsar.event.default.buttons
Value:
Start_Visit:Start Visit
End_Visit:End Visit
Display_Contact:Display Contact
Create_Call_Record:Create Call Record
View_Call_Record:View Call Record
Now define each individual button action:
Name: Event Start Visit Button
Key: pulsar.buttonActions.Event.Start_Visit
Value:
DEFAULT{
Action=SetVar;
VarName=Is_Started;
VarValue=Is_Started__c;
|
Action=SqlQuery;
QueryString=SELECT CASE WHEN '%%Is_Started%%' = 'TRUE' THEN 1 ELSE 0 END AS IsEventStarted;
QueryReturnFields=IsEventStarted;
QueryTest=%%IsEventStarted%%=1;
QueryTestTrue=EVENT_ALREADY_STARTED;
|
Action=SetField;
FieldType=TimeStamp;
FieldName=StartDateTime;
|
Action=SetField;
FieldType=General;
FieldName=Is_Started__c;
FieldValue=TRUE;
|
Action=SetLocation;
LocationType=DeviceLocation;
FieldName=Event_Location__c;
|
Action=Alert;
Message=Visit Has Been Started;
}
EVENT_ALREADY_STARTED{
Action=Alert;
Message=Visit has already started. You can only start the visit once;
}
Name: Event End Visit Button
Key: pulsar.buttonActions.Event.End_Visit
Value:
DEFAULT{
Action=SetVar;
VarName=Is_Ended;
VarValue=Is_Ended__c;
|
Action=SqlQuery;
QueryString=SELECT CASE WHEN '%%Is_Ended%%' = 'TRUE' THEN 1 ELSE 0 END AS IsEventEnded;
QueryReturnFields=IsEventEnded;
QueryTest=%%IsEventEnded%%=1;
QueryTestTrue=EVENT_ALREADY_ENDED;
|
Action=SetField;
FieldType=TimeStamp;
FieldName=EndDateTime;
|
Action=SetField;
FieldType=General;
FieldName=Is_Ended__c;
FieldValue=TRUE;
|
Action=Alert;
Message=Visit Has Been Ended;
}
EVENT_ALREADY_STARTED{
Action=Alert;
Message=Visit has already Ended. You can only end the visit once;
}
Name: Display Related Contact Button
Key: pulsar.buttonActions.Event.Display_Contact
Value:
DEFAULT{
Action=Display;
ObjectType=Contact;
ObjectIdField=WhoId;
}
Name: Display Related Contact Button
Key: pulsar.buttonActions.Event.Display_Contact
Value:
DEFAULT{
Action=Display;
ObjectType=Contact;
ObjectIdField=WhoId;
}
DEFAULT{
Action=SetVar;
VarName=Event_Id;
VarValue=Id;
|
Action=SqlQuery;
QueryString=Select COUNT () AS Count_Call_Records FROM Call_Record__c WHERE Related_Event__c = '%%Event_Id%%';
QueryReturnFields=Count_Call_Records;
QueryTest=%%Count_Call_Records%%>0;
QueryTestTrue=DISPLAY_MESSAGE;
|
Action=CreateAndMapFields;
ActionShouldComplete=TRUE;
ObjectType=Call_Record__c;
Related_Event__c=Id;
WhatId__c=WhatId;
WhoId__c=WhoId;
Subject__c=Subject;
Description__c=Description;
Start_Date_Time__c=StartDateTime;
End_Date_Time__c=EndDateTime;
}
DISPLAY_MESSAGE{
Action=Alert;
Message=You have already created a call record for this Event;
}
Action=SetVar;
VarName=Event_Id;
VarValue=Id;
|
Action=SqlQuery;
QueryString=select Id from Call_Record__c WHERE Related_Event__c = '%%Event_Id%%' LIMIT 1;
QueryReturnFields=@@QueryCount, Id AS CallRecord_Id;
QueryTest=%%QueryCount%%<=0;
QueryTestTrue=FAIL_NO_CALL_RECORD;
|
Action=Display;
ObjectType=Call_Record__c;
ObjectId=%%CallRecord_Id%%;
}
FAIL_NO_CALL_RECORD{
Action=Alert;
Message=No call records exist for this Event;
}
See the screenshots below to see the logic in action: