
Salesforce Apex / Visualforce Syntax Highlighter
Before I started to blog about Salesforce, I began looking for syntax highlighter wordpress plugins that might meet my needs. While the options were plentiful, none were specific to Salesforce and so I took it upon my self to develop my own. Now, to begin my first Salesforce post I share this plugin with you and a bit of information about how it came together.
Thanks to a post by Eric Santiago on his version of a Visualforce Syntax Highlighter for Typepad and a post by Alex on adding new brushes to Syntax Highlighter Evolved I was able to put together a WordPress plugin that works alongside the SyntaxHighlighter Evolved plugin in order to provide Apex & VisualForce sytanx highlighting.
You can download the plugin by clicking on this link: SyntaxHighlighter Evolved: Salesforce Apex & VisualForce Brush.
I’ve submitted the plugin to the wordpress.org depository so hopefully it will appear there soon.
Once you’ve installed both plugins, you can begin writing your code by using the following shortcodes:
[visualforce] [/visualforce]
[apex] [/apex]
Here’s an example of the Visualforce syntax:
<apex:page standardController="Opportunity" >
<apex:sectionHeader title="Cancellation Approval"/>
<apex:form >
<apex:pageBlock title="Edit" mode="edit" id="thepageblock">
<apex:pageblockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageblockButtons>
<apex:pageBlockSection columns="1" title="Opportunity Details">
<apex:outputField value="{!Opportunity.Name}"/>
<apex:outputField value="{!Opportunity.Customer_Name__c}"/>
<apex:outputField value="{!Opportunity.Hotel_Name__c}"/>
<apex:outputField value="{!Opportunity.Booked_Room_Nights__c}"/>
<apex:outputField value="{!Opportunity.Booked_Gross_Booking__c}"/>
<apex:outputField value="{!Opportunity.Request_To_Cancel__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Approval Details">
<apex:inputField value="{!Opportunity.Sales_Agent_Action__c}" required="true" />
<apex:inputField value="{!Opportunity.Cancellation_Is__c}" required="true" >
<apex:actionSupport event="onchange" rerender="thepageblock" status="status"/>
</apex:inputField>
<apex:inputField value="{!Opportunity.Sales_Agent_Outcome__c}" rendered="{!opportunity.Sales_Agent_Action__c == 'Called Customer' || opportunity.Sales_Agent_Action__c == 'Emailed Customer' || Opportunity.Cancellation_Is__c == 'Declined'}" required="true" style="width:500px;height:100px;"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here’s an example for the Apex syntax:
trigger CreateActivityFromPublicTask on Public_Task__c (after insert) {
List<Task> TasksToCreate = new List<Task>();
for (Public_Task__c pt : Trigger.new) {
Task t = new Task();
t.Priority = pt.Priority__c;
t.ActivityDate = pt.Call_Back_Date__c;
t.Call_Back_Time__c = pt.Call_Back_Time__c;
t.Call_Back_Number__c = pt.Call_Back_Number__c;
t.Description = pt.Comments__c;
t.WhoId = pt.Lead__c;
t.Status = pt.Status__c;
t.Type = pt.Type__c;
t.Subject = pt.Subject__c;
t.IsReminderSet = pt.IsReminderSet__c;
t.ReminderDateTime = pt.ReminderDateTime__c;
t.OwnerId = pt.OwnerId;
TasksToCreate.add(t);
}
if(TasksToCreate.size() > 0) {
insert TasksToCreate;
}
}