Salesforce Cookies #6

Adding Loading Icon on the page for an AJAX Request ( ActionFunction, CommandButton)

It’s always good to add a loading icon on the page when you are processing something on the server side (calling an apex method ) so a user can understand that something is running in the background. Following code snippet can be used along with your apex:actionFunction or apex:commandButton.

In Classic

<apex:actionStatus id="actionStatus">
  <apex:facet name="start" >
    <img src="/img/loading.gif" />
  </apex:facet>
</apex:actionStatus>

In Lightning Experience

<apex:actionStatus id="actionStatus">
  <apex:facet name="start" >
    <div class="slds-spinner_container">
      <div class="slds-spinner--brand slds-spinner slds-spinner--small" aria-hidden="false" role="alert">
        <div class="slds-spinner__dot-a"></div>
        <div class="slds-spinner__dot-b"></div>
      </div>
    </div>
  </apex:facet>
</apex:actionStatus>

Using ActionStatus in CommandButton

<apex:commandButton value="Save" action="{!Save}" status="actionStatus"/>

Happy Coding ūüôā

Salesforce Cookies#5

Uploading Attachment from Non-Salesforce Users ( Site or Guest Users) through Force.com sites

I came across a question on Trailblazers community where someone asked for a way to upload an attachment to a record and it should be accessible by non-salesforce users. I won’t go into much detail about that and will focus on providing the solution.

So, you just have to follow the below-mentioned steps to make it work for you.

  1. Setup a Force.com site if you haven’t already. You can get more details about this from this link.
  2. Create a VF page which lets an external user upload an attachment to Salesforce record.
  3. Add the page ( created in 2nd step) to the Site created in 1st step. Find more details here.

Visualforce page for Upload Attachment

You just need a VF page and here is the code gist which you can utilize and update as per your need.

Upload Attachment through Force.com sites

Happy coding ūüôā

 

Validate Visualforce form in lightning speed using VFValidator

While working on custom development, I found that form validation is the essential need for any developer in terms of data quality. I took a couple of hours to write code for the validation whether it is client side or server side and which gave me an idea to come up with a generic solution which can be used by any developer. To come up with a generic solution, I created one Visualforce component which can be embedded in any Visualforce page to validate the form.

Using VFValidator, you can do the common form validations. I am trying to evolve this as much as I can. I will try to keep my post very simple so everyone can be benefitted.

How to use VFValidator

Using VFValidator is very straightforward and quick. You just need to embed the VF component in your Visualforce page. Here is the syntax.

<c:VFValidator formId="FORM_ID"/>

FORM_ID : Form where you want to have the validation. 
By default its "frm" if you are not passing the ID.

After embedding the component, you will have to use some specific classes with your input components. Each class has its own purpose and there are limited classes which you can use. Here are the details about each class and its purpose.

  • required : To make a field required
  • email¬†: To check the¬†validity of the¬†email address
  • phone¬†: ¬†To verify a valid phone number, only allows 123-456-7890 format
  • number¬† : To restrict field for digits only
  • password: To check the password strength, Must be 8 characters and must contain¬†1 digit and special character

VFValidator Sample code

<c:VFValidator></c:VFValidator>
<apex:inputText id="firstName" styleClass="required slds-input" value="{!Contact.FirstName}"/>

Screenshot_1.png

If you want to check the demo of VFValidator then here is the VFValidator DEMO Link. I have also created a GitHub repository.

Please feel free to give your feedback. Thanks in advance!!