Delete All Scheduled Jobs in Salesforce Org

Sample Code:

//Get all scheduled jobs
List<CronTrigger> ctList = [SELECT Id, CreatedDate, CronExpression, CronJobDetailId, EndTime,
                            NextFireTime, OwnerId, PreviousFireTime, StartTime, State,
                            TimesTriggered FROM CronTrigger];
//Abort all jobs one by one
for(CronTrigger ct:ctList){
    System.abortJob(ct.Id);
}

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.50 out of 5)
Loading...

Salesforce Display Button On Apex Page Message

Apex Class:

public class SampleController {
    
    public Account acc {get;set;}
    public Boolean isButtonVisible {get;set;}
    public string message {get;set;}
    
    public SampleController(){
        isButtonVisible = false;
        acc = new Account();
        message = '';
    }
    
    public pageReference showMessage(){
        isButtonVisible = true;
        message = 'Do you want to create the account';
        return null;
    }
    
    public pageReference saveAccount(){
        insert acc;
        isButtonVisible = false;
        acc = new Account();
        return null;
    }
    
    public pageReference cancel(){
        isButtonVisible = false;
        acc = new Account();
        return null;
    }
}

Visualforce Page:

<apex:page controller="SampleController" tabStyle="Account">
    <apex:form >
        <apex:pageMessages escape="false"/> 
        <apex:outputPanel rendered="{!isButtonVisible}">
            <apex:pageMessage severity="info" strength="3" summary="{!message}">
                <apex:commandButton value="Yes" action="{!saveAccount}"/>
                <apex:commandButton value="No" action="{!cancel}"/>
            </apex:pageMessage>
        </apex:outputPanel>
        
        <apex:pageblock title="Account">
            <apex:pageBlockSection title="Account Information" columns="2">
                <apex:inputField value="{!acc.Name}"/>
                <apex:inputField value="{!acc.AccountNumber}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Confirm" action="{!showMessage}"> </apex:commandButton>
            </apex:pageBlockButtons>
        </apex:pageblock>
    </apex:form>
</apex:page>

Output:

Custom Label in JavaScript File

We use {!$Label.CustomLabelName}, when we call custom label in Visualforce page JavaScript function. But if we need to access custom labels in JavaScript file in static resource, then here is the way to get the custom label value.

Load the custom label in Visualforce Page before loading the static resource JavaScript file.

<script>
    window.$Label = window.$Label || {};
    $Label.MyCustomLable1 = '{!JSENCODE($Label.MyCustomLable1)}';
    $Label.MyCustomLable2 = '{!JSENCODE($Label.MyCustomLable2)}';
</script>

Use in JavaScript file.

console.log($Label.MyCustomLable1);
alert($Label.MyCustomLable1);

Open a visualforce page in same primary tab by closing the current primary tab in Salesforce console

{!REQUIRESCRIPT(“/support/console/36.0/integration.js”)}
{!REQUIRESCRIPT(“/soap/ajax/36.0/connection.js”)}
try {
sforce.console.getEnclosingPrimaryTabId(function (result)
{
sforce.console.openPrimaryTab(result.id, ‘/apex/CaseSummary?id={!Case.Id}’, true);
});
}
catch(ex){
alert(‘An Error has Occured. Error:’ + ex);
}

Dynamic Getting sObject Picklist Values on Lightning Component

In this example we will fetch Picklist field “Industry” values from “Account” object and set in ui:inputSelect on Lightning Component.

Apex Class:

public class GetPicklistValuesController {
    @AuraEnabled
    public static List <String> getPicklistValues(sObject obj, String fld) {
        
        List <String> pList = new list <String>();
        
        //Get the object type of the SObject.
        Schema.sObjectType objType = obj.getSObjectType();

        //Describe the SObject using its object type.
        Schema.DescribeSObjectResult objDescribe = objType.getDescribe();

        //Get a map of fields for the SObject
        Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();

        //Get the list of picklist values for this field.
        List<Schema.PicklistEntry > values = fieldMap.get(fld).getDescribe().getPickListValues();

        //Add these values to the selectoption list.
        for (Schema.PicklistEntry a: values) {
            pList.add(a.getValue());
        }
        pList.sort();
        return pList;
    }
}

Component:

<!--TestComponent-->
<aura:component controller="GetPicklistValuesController" access="global" implements="force:appHostable">
    <aura:attribute name="objInfo" type="account" default="{sobjectType : 'Account'}" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>    
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="select-01">Select Industry</label>
        <div class="slds-select_container">
            <ui:inputSelect  aura:id="accIndustry" class="slds-select"  change="{!c.onPicklistChange}"/>
        </div>
    </div>
</aura:component>

Component Helper:

({
    fetchPickListVal: function(component, fieldName, elementId) {
        var action = component.get("c.getPicklistValues");
        action.setParams({
            "obj": component.get("v.objInfo"),
            "fld": fieldName
        });
        var opts = [];
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state == "SUCCESS") {
                var allValues = response.getReturnValue();
                
                opts.push({
                    class: "optionClass",
                    label: "--- None ---",
                    value: ""
                });
                for (var i = 0; i < allValues.length; i++) {
                    opts.push({
                        class: "optionClass",
                        label: allValues[i],
                        value: allValues[i]
                    });
                }
                component.find(elementId).set("v.options", opts);
            }
        });
        $A.enqueueAction(action);
    },
})

Component Controller:

({
    doInit: function(component, event, helper) {
        helper.fetchPickListVal(component, 'Industry', 'accIndustry');
    },
    onPicklistChange: function(component, event, helper) {
        //get the value of select option
        alert(event.getSource().get("v.value"));
    },
})

Lightning App:

<!--TestApp-->
<aura:application extends="ltng:outApp" access="global">
    <c:TestComponent />
</aura:application>

Output: