• yumona joe
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Here's my code

Apex Class:
global class ASOverrideContacRegion implements Database.Batchable<sObject>{
    List<Contact> conlist = new List<Contact>();
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT MailingPostalcode,MailingCity,Region_Override__c,Region__c FROM Contact WHERE MailingPostalcode != null AND Region_Override__c = FALSE';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Contact> batch) {
        System.debug('batch=='+batch);
            
        Set<String> postcodes = new Set<String>();
        for (Contact a : batch) {
            postcodes.add(a.MailingPostalcode);
        } 
            
        Map<String,Id> mapregcode = new Map<String,Id>();
        for(Region__c reg: [SELECT Id,Postcode__c,Suburb_Name__c FROM Region__c WHERE Postcode__c IN :postcodes]) {
            mapregcode.put(reg.Postcode__c,reg.Id);
        }

        for(Contact con : batch) {
            if(mapregcode.containskey(con.MailingPostalcode)) {        
                Contact conTemp = new Contact();
                conTemp.Id = con.Id;
                conTemp.Region__c = mapregcode.get(con.MailingPostalcode);
                conlist.add(conTemp);
            }
        }

        System.debug('postcodes >>>> ' +postcodes);
        System.debug( 'mapregcode >>>>>' +mapregcode );
        update conlist;
        
        system.debug('conlist=='+conlist);
    }

    global void finish(Database.BatchableContext BC) {
    
    }
                                               
}


Test Class:

@isTest
public class ASOverrideContacRegionTest {
    
     
    static testMethod void setup(){
    List<Contact> tempConList = new List<Contact>();
        Contact con = new Contact();
      con.FirstName = 'Erin';
      con.LastName = 'Daly';
            con.MailingCity = 'Brisbane';
            con.MailingPostalCode = '4000'; 
            con.Region_Override__c = TRUE; 
      tempConList.add(con);
        insert tempConList;
    update tempConList;

    Contact con1 = new Contact();
      con1.FirstName = 'Erin';
      con1.LastName = 'Daly';
      con1.MailingPostalCode = '4008';
    insert con1;


        Region__c reg = new Region__c();
      // con.FirstName = 'Erin';
      // con.LastName = 'Daly'; 
            reg.Suburb_Name__c = 'Brisbane'; 
            reg.Postcode__c = '4000';
        insert reg;

        
      Test.startTest();
      ASOverrideContacRegion OCR = new ASOverrideContacRegion();
      Id jobId = Database.executeBatch(OCR);
      Test.stopTest();

    }

}

User-added image
Now I am doing a Superbadge assignment Lightning Experience Reports & Dashboards Specialist and I got the Error code that I have to use another DE. Or it can be fixed!  thanks.
Hi All,
          I want to show users like below image. how can i do this in LWC? any suggestions?
 User-added image