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 

Need Help on batch class

Fields on contact staging

Contact_Id__c,
Pronouns__c
Aboriginal_or_Torres_Strait_Islander__c, 
Date_of_Birth__c,
CALD__c,
Vaccination_status__c,
Require_an_interpreter__c, 
TIS_Interpreter_Language_Required__c, Safe_to_use_this_phone_number__c, 
Is_it_safe_to_use_this_email_address__c, Can_a_voicemail_be_left__c,
Street__c, 
City__c,
State_Province__c
Zip_Postal_Code__c
Country__c,
Why_is_this_their_current_location__c, 
Agency_Referral__c
Contact_Updated__c 

 

Need help to create a batch class for this the logic is to get all records on contact staging Then update the contact records base on the record info so in the photo below is the record needed to be created on contact staging and the contact Id is the same on contact the fields that are updated on contact staging will happen on contacts aswell


User-added image


did it make sense? Need Help. Thanks

CharuDuttCharuDutt
Hii Anonymous
Can Please Explain The Requirement On What Basis The Record Is Being Updated Or New Created
Anonymous DeveloperAnonymous Developer

Hi CharuDutt

when you create a new contact stage the contact Id must be an existing contact. the update happens when the contact staging record is created.

 

if the fields are not equal to null it updates and if the fields are null nothing will happen. does that make sense?

 

Thanks

Anonymous DeveloperAnonymous Developer

Hello CharuDutt

the code logic looks a lot like this butI'mm not sure how to write it

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;
does this make sense?