Monday 26 May 2014

Updating Records Through Custom Button(Javascript and Ajax api)

How to update some field value by using custom button ?
Lets assume we need to update Rating field value of Account Object,for this we will create a custom button on Account and will add that button in page layout. 

Here is an image of creating custom button.
Add caption

I am also sharing button code for updating field through ajax. 

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

var url = parent.location.href;
var connection = sforce.connection;
var accountRating = '{!Account.Rating}';
var accountId = '{!Account.Id}';


if(accountRating == 'Cold') {
   var updateAccountRecords = [];
   var update_Account = new sforce.SObject("Account")
   update_Account.Id = accountId;
   update_Account.Rating= 'HOT';
   updateAccountRecords.push(update_Account );
   sforce.connection.update(updateAccountRecords);
   alert('Account Rating is converted to HOT');
   window.location.reload();
} else if(accountRating == 'HOT'){
   alert('Already HOT');
}
else {
  alert('Only Cold Account rating can be converted to HOT');
  
}


Wednesday 21 May 2014

Adding Conditional Style Sheet To Particular Row On Pageblock Table

Hi All,
This post is regarding for adding style sheet on a particular table row.
Here I am sharing some example where table row is yellow,if account Type is Prospect.

This is my page
<apex:page controller="conditionalStyleController">
    <apex:form >
        <apex:pageBlock title="Accoiunt Table">
            <apex:pageBlockTable value="{!listOfAccounts }" var="account">
                <apex:column value="{!account.Name}" style="{!if(account.Type='Prospect','background-color:yellow;', 'color:black')}"/>
                   
               
                <apex:column value="{!account.Type}" style="{!if(account.Type='Prospect','background-color:yellow;', 'color:black')}"/>
            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>
</apex:page>

My Controller
public with sharing class conditionalStyleController {
    public list<Account> listOfAccounts{get;set;}
    public conditionalStyleController(){
        listOfAccounts = [SELECT id,Name,Type FROM Account];
    }
}

Here is the image of result.

Wednesday 14 May 2014

Renaming Tab and Field Labels

We should utilize the word which will be appropriate for customer business that is why sometimes we need to rename tabs and field label. 
For Custom field we can easily alter the field label name, however, this post is renaming standard field label.

How will we rename the tab and field label of any object?
 There are three section present to rename the tabs. 
  • Standard Tabs (For renaming standard object tab)
  • Custom Tabs (For renaming custom object tab)
  • Article Type
 

  • Now type new name for Account tab
  • Click Save,now Account tab is renamed.
  • Click on Next button to change field label. 

  • Change label name for all field and click on save button