• speedforce
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I have written one batch apex which will update contacts and records. There are about 2 million records which should be updated by this batch everytime it runs. Is it recommended to update all 2 million records at once, or is there any limit on updating the mass records? Or what is the recommended approach to do so?
I am new to Salesforce development and I am struggling in few things. I have to write a batch apex which will update few fields in all the contacts and accounts. There are few mappings which will be done cross object - like few fields from contacts will update theie value to a field in accounts object for that record. Here is what I have tried so far:
global class UpdateContactFields implements Database.Batchable<SObject>{
    global String query;
    global final String Entity;
    global final String email;
 
    global UpdateContactFields(String q, String e){
        query=q;
        Entity=e;
    }

    global Database.QueryLocator start(Database.BatchableContext BC){
        query = 'SELECT * FROM Contact LIMIT 10';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Contact> scope){
        List<Contact> contcts = new List<Contact>();
        //List<Account> accounts = new List<Account>();
        for(Contact c : scope){
            Contact cnt = (Contact)c;
            cnt.Pardot_End_Date_180_Prior__c       = cnt.End_Date_180_Prior__c;
            cnt.Pardot_Professional_Status__c     = cnt.Professional_Status__c;

            //need a way to pull the corresponding account here because of the field mapping to be done below
            //cnt.Pardot_Related_C_Account__c    = account.Related_C_Account__c ; //Pardot_Related_C_Account__c is in contacts and Related_C_Account__c is in accounts object

            contcts.add(cnt);
        }
        update contcts;
    }
    
    global void finish(Database.BatchableContext BC) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] {email});
        mail.setReplyTo('****@****.org');
        mail.setSenderDisplayName('Account and Contacts Batch Processing');
        mail.setSubject('Batch Process Completed - Salesforce');
        mail.setPlainTextBody('Batch Process has completed');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}
I dont know how to pull the corresponding account and do the field value assignment from account to contacts. Can someone please guide me through this. This is quite critical and I am stuck in it from sometime. Thank you.
I am very new to Salesforce and I need to write a trigger which should fire on few formula field updates and should update the other fields in contacts and accounts. So something like this:

Trigger should fire when updates are done to these fields:
From Contact object fields - ED_180_Prior__c (formula date field), Prof_Status__c (text)
From Account object fields - M_Status__c (formula text field), Days_of_MT__c (formula number field).

Trigger should update these fields:
From Contact object - Pardot_ED_180_Prior__c (date field), Pardot_Prof_Status__c (text).
From Accounts object - Pardot_M_status__c (text field), Pardot_Days_of_MT__c (number field)

I have tried this so far:

    trigger updatePardot on Contact (after insert)
    {
        List<contact> conUpdate = new List<Contact>();
        set<Id> sAccId = new set<Id>();
        for(Contact con: trigger.new) {
                sAccId.add(con.AccountId);
        }
        List<Account> lstAccount = [select id, Address_1__c, (select id,Address_1__c from contacts) from account where id IN: sAccId];
        for(Account acc: lstAccount) {
                for(Contact con: acc.contacts) {
                       //con.Address_1__c = acc.Address_1__c;
                       con.Pardot_ED_180_Prior__c = con.ED_180_Prior__c;
                       con.Pardot_Prof_Status__c = con.Prof_Status__c;
                       conUpdate.upsert(con);

                       acc.Pardot_M_status__c = acc.M_status__c;
                       acc.Pardot_Days_of_MT__c = acc.Days_of_MT__c;
                       lstAccount.upsert(acc);
           }
       }
   }

Can someone please help me if I am not doing it correct, or if I should change the approach as soon as possible? Also, should I setup workflow rules for every different field when this trigger should fire? Much thanks in advance.
I have written one batch apex which will update contacts and records. There are about 2 million records which should be updated by this batch everytime it runs. Is it recommended to update all 2 million records at once, or is there any limit on updating the mass records? Or what is the recommended approach to do so?
I am new to Salesforce development and I am struggling in few things. I have to write a batch apex which will update few fields in all the contacts and accounts. There are few mappings which will be done cross object - like few fields from contacts will update theie value to a field in accounts object for that record. Here is what I have tried so far:
global class UpdateContactFields implements Database.Batchable<SObject>{
    global String query;
    global final String Entity;
    global final String email;
 
    global UpdateContactFields(String q, String e){
        query=q;
        Entity=e;
    }

    global Database.QueryLocator start(Database.BatchableContext BC){
        query = 'SELECT * FROM Contact LIMIT 10';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Contact> scope){
        List<Contact> contcts = new List<Contact>();
        //List<Account> accounts = new List<Account>();
        for(Contact c : scope){
            Contact cnt = (Contact)c;
            cnt.Pardot_End_Date_180_Prior__c       = cnt.End_Date_180_Prior__c;
            cnt.Pardot_Professional_Status__c     = cnt.Professional_Status__c;

            //need a way to pull the corresponding account here because of the field mapping to be done below
            //cnt.Pardot_Related_C_Account__c    = account.Related_C_Account__c ; //Pardot_Related_C_Account__c is in contacts and Related_C_Account__c is in accounts object

            contcts.add(cnt);
        }
        update contcts;
    }
    
    global void finish(Database.BatchableContext BC) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] {email});
        mail.setReplyTo('****@****.org');
        mail.setSenderDisplayName('Account and Contacts Batch Processing');
        mail.setSubject('Batch Process Completed - Salesforce');
        mail.setPlainTextBody('Batch Process has completed');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}
I dont know how to pull the corresponding account and do the field value assignment from account to contacts. Can someone please guide me through this. This is quite critical and I am stuck in it from sometime. Thank you.