• mohd atif
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

I have written this class which is select the query of the Accounts and making an csv file.

cloud u please suggest me what to do to see the working of batch apex class,

 

 

 global class ConvertAccounts implements  Database.Batchable<sObject>
    {

        global final string query;
        global ConvertAccounts (String q)
    {
       query = q;
    }

global Database.QueryLocator start(Database.BatchableContext BC)
    {

           return Database.getQueryLocator(query);
    }


global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        folder f=[select id, name  from  folder  where Name='Accounts Details'];
        Document d = new Document();
        d.Name = 'Accounts CSV';
        d.folderid=f.id;
        string header = 'id , AccountNumber , name , AnnualRevenue , BillingCity , BillingCountry , Description , CreatedDate , ModifiedDate \n';
        string finalstr = header ;
     for(Account a: scope)
    {
       string recordString =   a.id+','+a.AccountNumber+','+a.Name+','+a.AnnualRevenue+','+a.BillingCity+','+a.BillingCountry+','+a.Description+','+a.CreatedDate+','+a.LastModifiedDate +'\n';
       finalstr = finalstr +recordString;
    }
    d.Body = Blob.valueOf(finalstr);
    d.ContentType = 'text/csv';
    d.Type = 'csv';
    insert d;
    update d;
 
}


global void finish(Database.BatchableContext BC)
{
  // Get the ID of the AsyncApexJob representing this batch job  
  // from Database.BatchableContext.    
  // Query the AsyncApexJob object to retrieve the current job's information.  

    AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,
    TotalJobItems, CreatedBy.Email
    from AsyncApexJob where Id =:BC.getJobId()];

  // Send an email to the Apex job's submitter notifying of job completion.  
     Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
     String[] toAddresses = new String[] {'!Account.EMail'};
     mail.setToAddresses(toAddresses);
     mail.setSubject('Apex Sharing Recalculation ' + a.Status);
     mail.setPlainTextBody('The batch Apex job processed ' + a.TotalJobItems +
     'batches with '+ a.NumberOfErrors + ' failures.');

     Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

}

For example,there is a text field like total marks,secured marks and percentage.
if i enter total marks =1000, and secured marks=781 and it automatical generate the field like 78.1% in percentage field.
we are able to do this after clicking on save button,but i wanna do this on screen an user can see it,when he clicks a tab button...

do u got it what i am saying.......??

Hi Guiders, could you please give me the neccessary steps how to Exporting And Importing  of Custom Fields from one developer edition to another developer edition