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
Anonymous DeveloperAnonymous Developer 

I have the logic in sched batch but i need help writing the code

Fields on contact staging:

Contact_Id__c,
Aboriginal_or_Torres_Strait_Islander__c, (checkbox)
Date_of_Birth__c, (date)
Vaccination_status__c, (picklist)
Agency_Referral__c (checkbox)
Contact_Updated__c  (checkbox)

 

the logic I am referring to is this i don't know if it makes sense.
 

Contact Staging List batch > List Contact Ids

Map<Id, Contact> idConMap = new Map <Id, Contact>
List contact toBeUpdated;

for ( Contact con : [Select Id, fields here FROM Contact WHERE Id in :listContIds] ) {
    idConMap.put( con.Id, con );
}

for ( Contact Staging a : batch ) {
    Contact mapCont = idConMap.get(a.ContactId__c);

    if ( a.field != null ) {
        mapCont.field = a.field;
    }

    toBeUpdated.add( mapCont );
}

update toBeUpdated;
I want to get all the records where Agency Referral is True
And Contact Updated = False. Need Help Thanks
mukesh guptamukesh gupta
Hi Exper,

Please use below code:-
 
global class UpdateContacts implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc)
    {
        String query= 'Select Id, Contact_Id__c,Aboriginal_or_Torres_Strait_Islander__c,Date_of_Birth__c,Vaccination_status__c,Agency_Referral__c ,Contact_Updated__c FROM Contact where Agency_Referral__c = true AND Contact_Updated__c = false';
        return Database.getQueryLocator(query); 
    }
    
    global void execute(Database.BatchableContext bc, List<Contact> scope)
    {
	 List<Contact> conList = new List<Contact>();
        for(Contact con: scope)
        {
            con.Agency_Referral__c =  false;  // here you can update accordingly 
            conList.add(con);
        }
        update conList;
    }
    
    global void finish(Database.BatchableContext bc)
    {
        
    }
}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
Anonymous DeveloperAnonymous Developer
hello Mukesh,

where is the mapping for contact Id?
Anonymous DeveloperAnonymous Developer
not the code that I was looking. 

contact staging object when a record is created the fields the fields on the contacts will be updated on the record that was written on contact staging record. does that make sense?