function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Preetham 345 SFDCPreetham 345 SFDC 

Implementation of Satus Bar or Progress Bar

Hello Every One,
I am trying to implement a bulk upload process for my client  by uploading a  csv file and Database.Insert class at the backend on the controller side.At the front end in the UI i am showing the user a visual Force page of data tabel(reading the data) which consits of data in csv file. Now I succeded till  insertion of all the records into saleforce which in csv file. Now i am in a plan to implement a 'Progress Bar' or 'Status Bar' which will pop up when user will click on Insert button and will update its status as per records get inserted(simillarly like status bar in data loader). If any one had worked on this kind of scenario , Could you please provide me a link or sample code so that would be easy for me  to implement it.

Thanks in Advance    
Avidev9Avidev9
Well you can easily add an action status to a action but that will be a static message or Gif image without any status information. I did some work around this and you can find the same here http://blogforce9.blogspot.in/2013/12/vfuiblock-simplified-wait-screen-for.html

N
ow if you want something to show numbers you probably have to read csv file using JS and chunkify the file. Now send the records using remoting and update the status in progressbar.
Preetham 345 SFDCPreetham 345 SFDC
Hi Avidev,
Thank's for your quick reply, how can we differentiate the records whether it is succes Insertor failure Insert using JavaScript.If possible can you provide some infromation on it . That will be very helpful to all of the people like me in the community.

Thanks
Preetam 
AshwaniAshwani
Preetam,

Javascript remoting or we can say Visualforce remoting is the solution to get status of success or failure of action performed by user on visualforce page. Look at the following example:

Apex:

global with sharing class AccountRemoter {

    public String accountName { get; set; }
    public static Account account { get; set; }
    public AccountRemoter() { } // empty constructor
    
    @RemoteAction
    global static Account getAccount(String accountName) {
        account = [SELECT Id, Name, Phone, Type, NumberOfEmployees 
                   FROM Account WHERE Name = :accountName];
        return account;
    }
}

Remoting on visialforce page:

<apex:page controller="AccountRemoter">
    <script type="text/javascript">
    function getRemoteAccount(name) {
        var accountName = name;

        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.AccountRemoter.getAccount}',
            accountName, 
            function(result, event){
                if (event.status) {
                   // Here is success
                } else if (event.type === 'exception') {
                    // Here is failure by your logic or custom exception
                } else {
                   // Here is failure of remote call. capture it by event.message
                }
            }, 
            {escape: true}
        );
    }
    </script>
    <button onclick="getRemoteAccount('Burlingten Textiles')">Get Account</button>
</apex:page>


Avidev9Avidev9
Well that should be easy. Have you used 
Database.insert()

earlier ?

You can have a insert method in controller and probably return the record count which succeded ?


Something like this should do
 

public static Integer insertAccount(List<Account> accts){
Database.SaveResult[] srList = Database.insert(accts, false);
Integer i =0;
for (Database.SaveResult sr : srList) {
    if (sr.isSuccess()) {
     i++;
   }
}
return i;
}


James LoghryJames Loghry
For another example of a progress bar, see tehnrd's awesome blog post: http://www.tehnrd.com/batch-apex-status-bar/