Showing posts with label sfdc. Show all posts
Showing posts with label sfdc. Show all posts

Wednesday, December 31, 2014

Adding and Deleting rows dynamically in pageblock table in Visualforce page.

Adding rows dynamically in pageblock table in Visualforce page.


Hi, 

In this post i am going to give sample example of how to add a row dynamically in pageblock table and how to remove the row from pageblock table dynamically.

For this i am developed one Visualforce page, One Controller and One Helper class. Initially i am loading the page with one row then after once the user clicks on AddRow button it is going to add 
one new row to that pagblock table. If you want to remove a particular row you can remove using Remove row link.



Visualforce Page:

<apex:page controller="AddMultipleAccountCLS">
<apex:form id="theForm">
 <apex:pageblock id="thePB" title="Creating Multiple Accounts">
  <apex:pageblockButtons >
   <apex:commandButton value="Save" action="{!SaveMultipleAccounts}"/>
  
  </apex:pageblockButtons>

  <apex:outputPanel id="accountHead">
  <apex:variable value="{!0}" var="rowNum"/>  
   <apex:pageBlockSection columns="1" title="Adding Multiple Accounts" id="thePbs" collapsible="False"> 
   
     <apex:pageBlockTable value="{!waAccList}" var="eachRecord"> 
      
      <apex:column headerValue="Action">
        <apex:commandLink value="Remove" style="color:red" action="{!removeRowFromAccList}" rendered="{!rowNum > 0}" rerender="accountHead" immediate="true" >
             <apex:param value="{!rowNum}" name="rowToRemove" assignTo="{!rowToRemove}"/>
         </apex:commandLink>
         <apex:variable var="rowNum" value="{!rowNum + 1}"/>
      </apex:column>
      
      <apex:column headerValue="Account Name">
                            <apex:inputField value="{!eachRecord.record.Name}" required="true"/>
       </apex:column>
      
      <apex:column headerValue="Account Number">
                            <apex:inputField value="{!eachRecord.record.AccountNumber}" required="true"/>
       </apex:column>
       
       
       <apex:column headerValue="Account Type">
                                <apex:inputfield value="{!eachRecord.record.Type}" required="true"/>
        </apex:column>
      
      <apex:column headerValue="Annual Revenue">
                                <apex:inputField value="{!eachRecord.record.AnnualRevenue}" required="true"/>
      </apex:column>   
    
    </apex:pageBlockTable>
   </apex:pageBlockSection>
   <apex:commandButton value="Add More" action="{!addNewRowToAccList}" rerender="accountHead" Status="status" immediate="true" />
   
  </apex:outputPanel>

 </apex:pageblock>
</apex:form>
  
</apex:page>

Controller Class:


public with sharing class AddMultipleAccountCLS {

    public PageReference SaveMultipleAccounts() {
    system.debug('controller save method is calling-->');
     AddMultipleAccountHelperCLS.save(waAccList);
    return null;
    }


 public List<WrapperpaAccountList> waAccList {get;set;}
 public Integer rowToRemove {get;set;}

 public AddMultipleAccountCLS(){
  waAccList = new List<WrapperpaAccountList>();
  addNewRowToAccList();
 }
 public void removeRowFromAccList(){
  waAccList = AddMultipleAccountHelperCLS.removeRowToAccountList(rowToRemove, waAccList);
   
 }

 public void addNewRowToAccList(){
     waAccList = AddMultipleAccountHelperCLS.addNewRowToAccList(waAccList);
    }
    
    

 public class WrapperpaAccountList{
        public Integer index {get;set;}
        public Account record {get;set;}
   } 
}


Controller Helper Class:

public class AddMultipleAccountHelperCLS {

    public static List<AddMultipleAccountCLS.WrapperpaAccountList> addNewRowToAccList(List<AddMultipleAccountCLS.WrapperpaAccountList> waAccObjList){
        AddMultipleAccountCLS.WrapperpaAccountList newRecord = new AddMultipleAccountCLS.WrapperpaAccountList();
        Account newAccountRecord = new Account();        
        newRecord.record = newAccountRecord;
        newRecord.index = waAccObjList.size();
        waAccObjList.add(newRecord);
        return waAccObjList;
    }
    
    
     public static List<AddMultipleAccountCLS.WrapperpaAccountList> removeRowToAccountList(Integer rowToRemove, List<AddMultipleAccountCLS.WrapperpaAccountList> waAccountList){
        waAccountList.remove(rowToRemove);
        return waAccountList;
    }
    
    public static void save(List<AddMultipleAccountCLS.WrapperpaAccountList> waAccList) {
        system.debug('==waAccList==>'+waAccList.size());
        List<Account> accountRecordsToBeInserted = new List<Account>();
        if(waAccList !=null && !waAccList.isEmpty()){
            for(AddMultipleAccountCLS.WrapperpaAccountList eachRecord : waAccList ){
                Account accTemp = eachRecord.record;
                accountRecordsToBeInserted.add(accTemp);
               
            }
            system.debug('==accountRecordsToBeInserted==>'+accountRecordsToBeInserted.size());
            insert accountRecordsToBeInserted;
        }
    }
}



This is about Dynamic row adding and Deleting functionality in Page Block table using Visualforce Tags.


Thanks..












Wednesday, December 24, 2014

Which API Should I Use in Salesforce? and What are the different API's available in salesforce.com?

Which API Should I Use in Salesforce? and
What are the different API's available in salesforce.com?

following user permission need:
User Permissions Needed – API Enabled under the profile level

Application Programming Interface (API)


API Name
What It’s For
When to Use It
Protocol
Data Format
Communication
REST API
Accessing objects in your organization using REST.
You want to leverage the REST architecture to integrate with your organization. No WSDL requirement.Well-suited for browser-based applications, mobile apps, and highly-interactive social applications.
REST
JSON, XML
Synchronous
SOAP API
Integrating your organization’s data with other applications using SOAP.
You have pre-existing middleware services that need to work with WSDLs and XML data.
SOAP/WSDL
XML
Synchronous
Chatter REST API
Accessing Chatter feeds and social data such as users, groups, followers, and files using REST.
You want to integrateChatter into a variety of applications, such as mobile apps, intranet sites, and third-party Web applications.
REST
JSON,
  XML

Synchronous (photos are processed asynchronously)
Bulk API
Loading or deleting large numbers of records.
You have over a million records to process and speed is a requirement.
REST
csv,xml
Asynchronous
Metadata API
Managing customizations in your organization and building tools that can manage the metadata model, not the data itself.
You want to migrate changes, such as custom object definitions and page layouts, from a sandbox to your production environment.
SOAP/WSDL
XML
Asynchronous
Streaming API
Providing a stream of data reflecting data changes in your organization.
You need near real-time notifications of when records are created or updated.
Bayeux
JSON
Asynchronous (stream of data)
Apex REST API
Building your own REST API in Apex. ExposesApex classes as RESTful Web services.
You need to build custom JSON responses or you want to expose custom functionality that you implemented in Apex.
REST
JSON, XML, Custom
Synchronous
Apex SOAP API
Creating custom SOAP Web services in Apex. Exposes Apex classes as SOAP Web services.
You need to build custom XML responses or you want to expose custom functionality that you implemented in Apex .
SOAP/WSDL
XML
Synchronous
Tooling API
Building custom development tools forForce.com applications
You want to add functionality to your existing development and integration tools or you want to build specialized development tools for a specific application or service.
REST and SOAP
JSON, XML, Custom
Asynchronous


For More Details, click here









Monday, December 22, 2014

How to add the new line in Salesforce Custom Label

How to add the new line in Salesforce Custom Label

Create a new Custom Label using below path:

Under Setup-> Build -> Create -> Custom Labels -> Click New and create a new custom Label called ‘Test With Line Breaks




Add the Value like:
Thanks & Regards, <br/>
sfdcsrini.blogspot.com Team <br/>
Testing by sfdcsrini.blogspot.com <br/>

and Save it.


How to Use the Custom Label in Visualforce Page:
<apex:outputText value=”{!$Label.Test_With_Line_Breaks}” escape=”false” /> make sure escape=”false”










Saturday, December 20, 2014

Dashboards in Salesforce.com

Dashboards in Salesforce.com

 

Dashboard is an amazing medium by which the companies whole information can be shared with the CEO as a SCREENSHOT. Some important things to know about Dashboard are:

 

*With Dashboard a user can even see the information to which he does not has the access, Thanks to the concept of Running User - ADM 201, CON 201, DEV 401 Certification Question

*One can have only 2 or 3 columns in a Dashboard - ADM 201 Certification Question
*In Home, Dashboard component you only see the FIRST ROW of the source dashboard - ADM 201 certification question

*You can restrict the access to a dashboard by restricting the access to a folder in which that dashboard is placed

*Dashboards can be scheduled to run any time during a day and you can get them delivered via an Email

*Dashboards can only be created with custom reports as the source reports. One can not have the standard reports as the source reports for the Dashboard – ADM 201 Certification Question

*Only 20 components can be added to a dashboard - ADM 201 Certification Question
*Deleted Dashboards can be retrieved from the Recyclebin




 

Friday, December 19, 2014

Inline Editing in Salesforce.com

Inline Editing in Salesforce.com

 

Salesforce.com provides Inline Editing feature which is applicable to the entire organization – ADM 201 Certification Question

Inline editing is a feature by which one can edit a record without pressing the edit button. User goes to the detail page, doubles click on a field, changes to a new value and presses save. This process makes sure the field value is updated to the new value.

Inline editing limitations:-
  • Does not work for all fields, some fields are exception to Inline editing like opportunity stage.
  • Inline editing can not be turned on for one user and turned off for another. It is global and works for all or none – ADM 201 Certification Question
To set inline editing go to: Setup – customize – UI Settings – inline editing

Business advantage:- Saves on the no. of clicks required to edit a record.

Point to Remember:- If you have changed a value using Inline Editing but forgot to press the save button then those changes will not be saved and will get discarded as soon as you close that particular window.

 

 


Sunday, June 15, 2014

How To Use APEX:COMMANDBUTTON In Visualforce Page?

How To Use APEX:COMMANDBUTTON In Visualforce Page?

<apex:commandButton>:

 Buttons are very important in any page and they are the means using which a user interacts with the system to perform some actions such as Save, Update, Create, Delete, Cancel etc... 

This tag helps us to create buttons.The action that has to be executed when the button is pressed depends on the ACTION attribute specified in this tag. The action that is specified needs to be defined in the controller that is used in this pages controller attribute of the page tag. Once the action is performed the page would navigate to a different page or display the same page based on the PageReference variable that is returned by the action.

An < apex:commandButton > component must always be a child component of the < apex:form > tag. 

syntax:
<apex:commandButton action="{!save}" value="Save" id="save"/>

This tag supports following attributes:

Attribute
Description
Id
An identifier that allows the commandButton component to be referenced by other components in the page.
Image
The absolute or relative URL of the image displayed as this button. If specified, the type of the generated HTML input element is set to "image."
Immediate
A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.
onblur
The JavaScript invoked if the onblur event occurs that is, if the focus moves off of the command button.
onclick
The JavaScript invoked if the onclick event occurs that is, if the user clicks the command button.
oncomplete
The JavaScript invoked when the result of an AJAX update request completes on the client.
ondblclick
The JavaScript invoked if the ondblclick event occurs that is, if the user clicks the command button twice.
onfocus
The JavaScript invoked if the onfocus event occurs that is, if the focus is on the command button.
onkeydown
The JavaScript invoked if the onkeydown event occurs that is, if the user presses a keyboard key.
onkeypress
The JavaScript invoked if the onkeypress event occurs that is, if the user presses or holds down a keyboard key.
onkeyup
The JavaScript invoked if the onkeyup event occurs that is, if the user releases a keyboard key.
onmousedown
The JavaScript invoked if the onmousedown event occurs that is, if the user clicks a mouse button.
onmousemove
The JavaScript invoked if the onmousemove event occurs that is, if the user moves the mouse pointer.
onmouseout
The JavaScript invoked if the onmouseout event occurs that is, if the user moves the mouse pointer away from the command button.
onmouseover
The JavaScript invoked if the onmouseover event occurs that is, if the user moves the mouse pointer over the command button.
onmouseup
The JavaScript invoked if the onmouseup event occurs that is, if the user releases the mouse button.
rendered
A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
reRender
The ID of one or more components that are redrawn when the result of an AJAX update request returns to the client. This value can be a single ID, a comma-separated list of IDs, or a merge field expression for a list or collection of IDs.
status
The ID of an associated component that displays the status of an AJAX update request. See the actionStatus component.
style
The style used to display the commandButton component, used primarily for adding inline CSS styles.
styleClass
The style class used to display the commandButton component, used primarily to designate which CSS styles are applied when using an external CSS stylesheet.
tabindex
The order in which this button is selected compared to other page components when a user presses the Tab key repeatedly. This value must be a number between 0 and 32767, with component 0 being the first component that is selected when a user presses the Tab key.
timeout
The amount of time (in milliseconds) before an AJAX update request should time out.
title
The text to display as a tooltip when the user's mouse pointer hovers over this component.
value
The text displayed on the commandButton as its label.



Visualforce Example:

<apex:page standardController="Account">
    <apex:form >
        <apex:pageBlock title="My Content" mode="edit">
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!account.name}"/>
                <apex:inputField value="{!account.site}"/>
                <apex:inputField value="{!account.type}"/>
                <apex:inputField value="{!account.accountNumber}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>










This tag supports following attributes:

 
| ,