Wednesday 27 November 2013

Randomly Generate Html Color

Are you fed up of copying Hex color code and changing it again and again and do you want to Generate Html Color code randomly, you can acheive this using following javascript code.

<script>
    function get_random_color() {
        var letters = '0123456789ABCDEF'.split('');
        var color = '#';
        for (var i = 0; i < 6; i++ ) {
            color += letters[Math.round(Math.random() * 15)];
        }
        document.getElementById("in").setAttribute('style','background-color:' +color);
    }

</script>

I am generating the color randomly on click of button.

<div id="d">
  <input type="text" id="in"/>
  <input type="button" onClick="get_random_color();" value="generate"/>

</div>


Tuesday 26 November 2013

Style your Button

Fed up with your look and feel of your old buttons and wanted to add more appeal to your html button
then I will show you the way to get rid of that old boring style button.

  

In your Input button
<input type="button" value="Button" id="btn" />

You just have add this CSS:


and you will get a new Stylish button, modified it further as you want.


Monday 25 November 2013

How to Use vLookup in Excel

Many Times I find people struggling to use vLookup in excel as they find it difficult. So today I will tell you how can you use vLookup in Excel and for demo we will be using vlookup for two different Excel sheets.

I have created two reports
1. Account with Contacts
(Account and Contact.csv)


2. Account with Opportunity
(Account and Opportunity.csv)





and export them.

We will use vLookup function to get Account Name From Sheet 2(" Account and Opportunity") to Sheet 1(" Account and Contact")

Step 1.write =vlookup( in a cell where you want to find out the value. 
You can also try this with clicking fx present.

Step 2. Click on cell A3 as we want to find out the Account name for that cell.On clicking you will see 'A3' automatically populated inside vlookup() function.


 
 
 
Step 3. Now go to second sheet and select the columns where you want to search the Account name for that particular Id. You will see the vlookup get automatically updated with the columns range.


 
Step 4. Your vlookup looks like
=vlookup(A3,'[Account and Opportunity 1.csv]Account and Opportunity 1'!$A$1:$C$33,
add the columns number where Account Name is, in our case Account number is at Column 2 in sheet 2.

Step 5. Now put 0 as fourth and final argument and close the vlookup function. Your vlookup will look like
 
=vlookup(A3,'[Account and Opportunity .csv]Account and Opportunity 1'!$A$1:$C$33,2,0)
 
now on click of enter Account Name will appears.


Thursday 21 November 2013

SFDC : Custom Message on Visualforce

Many times when we creating our visualforce page, we want to our 
custom Information Message, Error or Warning on our visualforce page on satisfying some validation. Salesforce provide few messaging ways which are

1) apex:pageMessage
It is used to display single custom method using Salesforce formatting. we  can decide its severity.

on vF page



severity can also be WARNING, INFO

for more info go to :

2) apex:pageMessages
It is used to display all messages on page, it will display all the custom messages as well as Salesforce generated messages on page.

vf code:
 Controller :

vF page looks something like this:


have you noticed how pageMessages handles all the Error, Warning, Info messages on page, pageMessages is used mostly on vf page.


for more info go to :
3) apex:message :
It is used to display the error message only on a specific field. Allow developers to place specific error for specific field.

vf code :
 
 controller : 

vf page will looks something like this :
as you can see error message is appears for Name field as it is associate only with it, which is mention in <apex:message for="accname"/> where accname is id of inputfield <apex:inputField value="{!account.Name}" id="accname"/>.

for more information go to :
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_message.htm

4) apex:messages :
It is similar to apex:message or you can say it is a composition of all the errors.It will display all the errors but these errors will be displayed as a list with no styling.

Example:

vf code :

controller :


vf page will looks like :

 for more information go to:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_messages.htm



Now do all of them together:

vf code :
controller :

vf page will looks like :

Hope that will solve your confusion among pageMessage, pageMessages, message, messages

Thanks.

Monday 18 November 2013

Visualforce is a great for rapidly building web apps on top of Salesforce. One of the features of Visualforce is called "Satic Resource". It allows developers to add any custom Javascript, CSS and image files to Salesforce server and provide them a way to extend Visualforce capabilities to build different kinds of applications.
                  Is is a good practice to write a Javascript and save in satatic resource and include it your code.

Example :

Suppose you are creating a page and have few buttons ( save, cancel ) on the page and you want to pop up a confirmation message when user click on cancel button.
Then first create a file where you will writting all your javascript code.
I have created confirm.js which contain my javascript code 

 


 Saved that file in Static Resource, I saved my file in static resource with name wizradConfirm.



and then include that in my visualforce code. (Highlighted in red)
 <apex:page controller="oppController">
     <apex:includeScript value="{!$Resource.wizardconfirm}"/>
     <apex:form>
         <apex:pageBlock title="Opportunity Information" mode="edit">
                <apex:pageBlockButtons >
                    <apex:commandButton action="{!step1}" value="Previous"/>
                    <apex:commandButton action="{!step3}" value="Next"/>
                    <apex:commandButton action="{!Cancel}" value="Cancel"    onclick="return confirmCancel()" immediate="true"/>
                </apex:pageBlockButtons>

         </apex:pageBlock>
     </apex:form>
</apex:page>


so when User clicks cancel pop up message shows up.