• KCali12
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I've never used a map in an Apex class before, but I think this scenario requires one, and I need help.

I have a custom object called Time_Allocation__c with the following fields:
  • Unit_Subunit__c (Formula field - string)
  • Time_Sheet_Allocated_Hrs__c (Lookup to to Time_Sheet_Allocated_Hrs__c object)
  • Time_Sheet__c (Lookup to Time_Sheet__c object)

With my batch Apex, which is querying all Time_Allocation__c records where the Time_Sheet_Allocated_Hrs__c field is null, I need to do the following:
  1. Create one Time_Sheet_Allocated_Hrs record for each Time_Sheet__c/Unit_Subunit__c combination.
  2. Populate the Time_Allocation__c record with the appropriate Time_Sheet_Allocated_Hrs__c lookup field (based on the appropriate Time_Sheet_c/Unit_Subunit__c combo.
Here is my class so far:
 
global class TSAllocatedHrsBatch implements
    
    Database.Batchable<sObject>{
        
        global Database.QueryLocator start(Database.BatchableContext bc){
        	return Database.getQueryLocator(
        	[SELECT Id, Time_Sheet_Allocated_Hrs__c, Time_Sheet__c, Unit_Subunit__c  from Time_Allocation__c where 
         	Type__c = 'Program Time' AND Time_Sheet_Allocated_Hrs__c = null order by Time_Sheet__c]);
    }
        
        global void execute(Database.BatchableContext bc, List<Time_Allocation__c> batchList){
		

      		Set<Id>taIds = new Set<Id>();
            Set<String>UnitSubList = new Set<String>();
            Set<Id>TimeSheetIds = new Set<Id>();
         
            
            for (Time_Allocation__c ta : batchList){
                	taIds.add(ta.Id);
                	UnitSubList.add(ta.Unit_Subunit__c);
                	TimeSheetIds.add(ta.Time_Sheet__c);
                	
             Map<Id,String> tsAllHrsMap = new Map<Id, String>();
                tsAllHrsMap.put(ta.Time_Sheet__c, ta.Unit_Subunit__c);
                       
            }
                       
            //Now what?

      
            List<Time_Sheet_Allocated_Hrs__c> tsAllHrsListInsert = new List<Time_Sheet_Allocated_Hrs__c>();

            
            insert tsAllHrsListInsert;
            }
            
                        
    	global void finish(Database.BatchableContext bc) {
     
    }
    }


After putting the values I want in the map, how do pick out the values to create the individual Time_Sheet_Allocated_Hrs__c records that I want to insert?  Again, I only want one record for each Time_Sheet_c/Unit_Subunit__c combination, so I also need to figure out how to avoid creating duplicates.

Do I need a map of a map to do this?  If so, what syntax do I use?

Thanks for any guidance you can offer.

 
I've never used a map in an Apex class before, but I think this scenario requires one, and I need help.

I have a custom object called Time_Allocation__c with the following fields:
  • Unit_Subunit__c (Formula field - string)
  • Time_Sheet_Allocated_Hrs__c (Lookup to to Time_Sheet_Allocated_Hrs__c object)
  • Time_Sheet__c (Lookup to Time_Sheet__c object)

With my batch Apex, which is querying all Time_Allocation__c records where the Time_Sheet_Allocated_Hrs__c field is null, I need to do the following:
  1. Create one Time_Sheet_Allocated_Hrs record for each Time_Sheet__c/Unit_Subunit__c combination.
  2. Populate the Time_Allocation__c record with the appropriate Time_Sheet_Allocated_Hrs__c lookup field (based on the appropriate Time_Sheet_c/Unit_Subunit__c combo.
Here is my class so far:
 
global class TSAllocatedHrsBatch implements
    
    Database.Batchable<sObject>{
        
        global Database.QueryLocator start(Database.BatchableContext bc){
        	return Database.getQueryLocator(
        	[SELECT Id, Time_Sheet_Allocated_Hrs__c, Time_Sheet__c, Unit_Subunit__c  from Time_Allocation__c where 
         	Type__c = 'Program Time' AND Time_Sheet_Allocated_Hrs__c = null order by Time_Sheet__c]);
    }
        
        global void execute(Database.BatchableContext bc, List<Time_Allocation__c> batchList){
		

      		Set<Id>taIds = new Set<Id>();
            Set<String>UnitSubList = new Set<String>();
            Set<Id>TimeSheetIds = new Set<Id>();
         
            
            for (Time_Allocation__c ta : batchList){
                	taIds.add(ta.Id);
                	UnitSubList.add(ta.Unit_Subunit__c);
                	TimeSheetIds.add(ta.Time_Sheet__c);
                	
             Map<Id,String> tsAllHrsMap = new Map<Id, String>();
                tsAllHrsMap.put(ta.Time_Sheet__c, ta.Unit_Subunit__c);
                       
            }
                       
            //Now what?

      
            List<Time_Sheet_Allocated_Hrs__c> tsAllHrsListInsert = new List<Time_Sheet_Allocated_Hrs__c>();

            
            insert tsAllHrsListInsert;
            }
            
                        
    	global void finish(Database.BatchableContext bc) {
     
    }
    }


After putting the values I want in the map, how do pick out the values to create the individual Time_Sheet_Allocated_Hrs__c records that I want to insert?  Again, I only want one record for each Time_Sheet_c/Unit_Subunit__c combination, so I also need to figure out how to avoid creating duplicates.

Do I need a map of a map to do this?  If so, what syntax do I use?

Thanks for any guidance you can offer.

 
Hello Helplers

I  have a question related  to  Lihtning:dataTable  componenent
There is an option  the  CLIP  or WRAP  the test  in a cell.
By  Default CLIP  is used and user  can switch to WRAP

What I  want is  to  have the  WRAP  being defaulted

Is  there any  solution for this?

Thanks in advance
Csbaa 
It's a basic question. How to rename Lightning component once created?  I couldn't find any menu on Devloper console and any buttons on Setup|Develop|Lightning Components. Is it necessary to delete and create new one with new name?