• TK1234
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 9
    Replies
Can someone please advise how to achieve displaying new custom button record type based.

Custom object -> Engineer profile 
Record type --> software eng profile
                          hardware eng profile.
I should show  different "NEW" page based on the records types override the standard "New" button features. 
  • March 20, 2018
  • Like
  • 0
Hi Experts,

I have an object ( say Account) and defined a self relationship Account object which is 1 parent Account can have multiple child Accounts.

Now I have to get the count of child objects  from  the related list and update the count in parent... how to do achieve this?

Appreciate your inputs...

 
  • March 14, 2018
  • Like
  • 0

Hi Experts,

I am trying to do bulk insert of new accounts in SF using batch apex concept.
 I went thru the Database.Batchable<sObject>  and guess the records fetched in Database.QueryLocator is what processed in execute method .... which means it does only update/delete? how to insert record?

how i can accomblish inserting new records in bulk >50k in SF. Kindly assist.

Also to start with i  tried with update... I dont see any records updated.... instead i see in console with message ("source for Batch Apex could not be loaded) here is the sample.... please let me know where am missing.

global class batchExample implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        // collect the batches of records or objects to be passed to execute         
        String query = 'SELECT Id,Name FROM Account limit 10'  ;         
        return Database.getQueryLocator(query);       
    }
     
    global void execute(Database.BatchableContext BC, List<Account> scope) {
        List<Account> accList = new List<Account>();
        // process each batch of records
          for (integer i=0;i<100;i++)
                {
        Account anew= new Account(Name ='theanu'+i,BillingCity='SA port'+i,Phone='1212'+i);
        accList.add(anew);         
            
               }
         
        try {
            // Update the Account Record
            insert accList;
            
         
         
        } catch(Exception e) {
            System.debug(e);
        }
         
    }        
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
       
  }
}



 

  • February 20, 2018
  • Like
  • 0
Hi Experts,

I have an object ( say Account) and defined a self relationship Account object which is 1 parent Account can have multiple child Accounts.

Now I have to get the count of child objects  from  the related list and update the count in parent... how to do achieve this?

Appreciate your inputs...

 
  • March 14, 2018
  • Like
  • 0

Hi Experts,

I am trying to do bulk insert of new accounts in SF using batch apex concept.
 I went thru the Database.Batchable<sObject>  and guess the records fetched in Database.QueryLocator is what processed in execute method .... which means it does only update/delete? how to insert record?

how i can accomblish inserting new records in bulk >50k in SF. Kindly assist.

Also to start with i  tried with update... I dont see any records updated.... instead i see in console with message ("source for Batch Apex could not be loaded) here is the sample.... please let me know where am missing.

global class batchExample implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        // collect the batches of records or objects to be passed to execute         
        String query = 'SELECT Id,Name FROM Account limit 10'  ;         
        return Database.getQueryLocator(query);       
    }
     
    global void execute(Database.BatchableContext BC, List<Account> scope) {
        List<Account> accList = new List<Account>();
        // process each batch of records
          for (integer i=0;i<100;i++)
                {
        Account anew= new Account(Name ='theanu'+i,BillingCity='SA port'+i,Phone='1212'+i);
        accList.add(anew);         
            
               }
         
        try {
            // Update the Account Record
            insert accList;
            
         
         
        } catch(Exception e) {
            System.debug(e);
        }
         
    }        
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
       
  }
}



 

  • February 20, 2018
  • Like
  • 0
Hello,
I have a batch job which runs to populate two objects.. Monthly Activity(MonAct) and URL Individual monthly Activity (URLIndMonAct)...
The problem with the response is that I am quering for MonAct records and I am getting back 5 of them . And each of those MonAct records contains with it thousands of URLIndMonAct records...

I have limited my query to just 2 records per batch but I am still getting DML Rows : 10001 error ..
If I redice the size to 1 record, the batch is running for too long...

Can any one please guide me, how can I modify my code to prevent this error and not lose any records while processing...
Any help is appreciated.

Thanks!
global class BatchToUpdateGARecords implements Database.Batchable<sObject>, Database.Stateful, Schedulable, Database.AllowsCallouts{

    private List<String> EMAIL_BATCH_RESULTS = new List<String>{System.Label.Email_List};  
    global  IndividualMonthlyGARecords.BatchResponse runningBatchResponse;
    private String query;
    private Integer queryYear;
    private Integer queryMonth;

    global BatchToUpdateGARecords(Integer year, Integer month){
        runningBatchResponse = new IndividualMonthlyGARecords.BatchResponse();

        // Validate user input, if request to run batch is not for todays date
        if(month != null && year != null && month >= 0 && month <= 12 && year > 1950){
            this.queryYear  = year;
            this.queryMonth = month;
        }
        else{
            Date yesterdaysDate = Date.today().addDays(-1);

            this.queryYear  = yesterdaysDate.year();
            this.queryMonth = yesterdaysDate.month();
        }

        this.query  = 'SELECT Id, GID__c ';
        this.query += 'FROM Monthly_Activity__c ';
        this.query += 'WHERE Year__c = ' + queryYear + ' ';
        this.query += 'AND Month__c = ' + queryMonth + ' ';
        this.query += 'AND GID__c <> null ';
        this.query += 'AND GID__c > 0 ';
        
    }

    global BatchToUpdateGARecords(){
        this(null, null);
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Monthly_Activity__c> currentBatchRecords){
	
        List<Monthly_Activity__c> MonthlyActivities = [
            SELECT Id, GID__c, Month__c, Year__c
            FROM Monthly_Activity__c 
            WHERE Year__c =: queryYear
            AND Month__c =: queryMonth
            AND GID__c IN: Pluck.decimals('GID__c', currentBatchRecords)
        ];        

        List<URL_Individual_Monthly_Activity__c> urlIndividualMonthlyActivities = [
            SELECT Id, GID__c, URL__c, Month__c, Year__c
            FROM URL_Individual_Monthly_Activity__c 
            WHERE Year__c =: queryYear
            AND Month__c =: queryMonth
            AND GID__c IN: Pluck.decimals('GID__c', currentBatchRecords)
        ];        
         
        if(MonthlyActivities.isEmpty()){
            return;
        }
    
        try{           
            IndividualMonthlyGARecords.batchHandlerToUpdateRecords(
                runningBatchResponse,
                MonthlyActivities,
                urlIndividualMonthlyActivities,
                queryYear,
                queryMonth
            );
        
       }catch(exception ex){
            system.debug('exception call :'+ ex.getMessage());
            system.debug('exception call line :'+ ex.getStackTraceString());
        }
        if(runningBatchResponse != null && !runningBatchResponse.getSuccessRecords().isEmpty()){
            List<Database.SaveResult> updateResults =
                Database.update(runningBatchResponse.getSuccessRecords(), false);

            for(Database.SaveResult updateResult : updateResults){
              if(!updateResult.isSuccess()){
                for(Database.Error err : updateResult.getErrors()){
                  runningBatchResponse.addDatabaseError(err.getMessage());
                }
              }
            }
        }

        runningBatchResponse.clearSuccessRecords();
    
        if(runningBatchResponse != null && !runningBatchResponse.getSuccessRecordsIMA().isEmpty()){

            List<Database.SaveResult> updateResults1 =
                Database.update(runningBatchResponse.getSuccessRecordsIMA(), false);

            for(Database.SaveResult updateResult1 : updateResults1){
              if(!updateResult1.isSuccess()){
                for(Database.Error err : updateResult1.getErrors()){
                  runningBatchResponse.addDatabaseError(err.getMessage());
                }
              }
            }
        }

        runningBatchResponse.clearSuccessRecords();
  
    }

    global void execute(SchedulableContext SC){
        Database.executeBatch(new BatchToUpdateGARecords(), 2);                            //Changed from 5    }
    
    global void finish(Database.BatchableContext BC){
        AsyncApexJob apexBatchResult = [
            SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id =: BC.getJobId()
        ];
    
        // Generate email body
        String emailBody = 'Apex Batch to Update PageviewSessions processed '
            + apexBatchResult.TotalJobItems + ' batches with '+ apexBatchResult.NumberOfErrors + ' failures.\n\n'
            + 'Database errors (if any): ' + JSON.serialize(runningBatchResponse.getDatabaseErrors()) + '\n';
        
        // Extract error string from batch response
        //emailBody += runningBatchResponse.generateErrorString();

        // Send email
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(EMAIL_BATCH_RESULTS);
        mail.setSenderDisplayName('About.com Experts - Batch Results');
        mail.setSubject('About.com - Batch to Update PageviewSessions - status: ' + apexBatchResult.Status);
        mail.setPlainTextBody('Batch Process has completed\n\n' + emailBody);

        Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{mail});
    }
}

 
1. what is batch apex..?
2.y u r going to batch appex..?
3.step to do batch apex..?
4.what is  Database.Stateful..? eaht the use for it..
5.if record are fail how we find..>
6.what is schedule apex and use and difference between them..?
 
So the structure I have is this:

Record of Custom Object Type A has a related list of multiple records of Custom Object Type B.


And this is what I'm looking to do:

Object Type B has a Currency field, and Object Type A has a field that is inteded to be the Sum of that Currency field for all records in the related list. Whenever any record of Object Type B is updated, I need the Sum field on Object Type A to calculate the new sum. (Essentially it is a rollup sum, but I cannot use a rollup field because these do not have a Master-Detail relationship.)


Example:

Initial State:
  • Object Type A Record SumField = 100
    • Related ObjectB Record 1 CurrencyField = 50
    • Related ObjectB Record 2 CurrencyField = 30
    • Related ObjectB Record 3 CurrencyField = 20
User Action:
  • Related ObjectB Record 2 CurrencyField is changed from 30 to 80
Desired End State:
  • Object Type A Record SumField = 150
    • Related ObjectB Record 1 CurrencyField = 50
    • Related ObjectB Record 2 CurrencyField = 80
    • Related ObjectB Record 3 CurrencyField = 20