• Jay Gatsby
  • 20 Points
  • Member since 2018

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
  • 0
I have this requirement in my project, its called post refresh activity. We have refreshed our sandbox from production. Now we have 30+ master rescords to be inserted into sandbox, we can do it manually via, Dataloader/online Dataloader.io but its time consuming.

Now I want to make it automatic, like reading these csv files in apex class and insert data/records to respective objects. I have just overview of this, but i am not sure from where do i start.

It will be helpful if anyone can guide me little bit.

I have below sample method

    private static Map<String,Object> getSampleMap(List<Object> sampleList){
        Map<String,Object> sampleMap = new Map<String,Object>();
        if(sampleList!= null && sampleList.size()>0 ){
            for(Object obj : sampleList){
        return sampleMap ;
User-added image
Two custom objects:
2.Unit__c and Master-detail with Building__c

i wrote trigger on my unit object

/*trigger addUnitTrigger on Unit__c (after insert, after update) {
    List<Building__c>   building = [select id from Building__c];
    List<Id> id= new List<Id>();
    for(Building__c b: building){
    List<Unit__c>  unit  = [select Add_Units__c, id,Building__c from Unit__c where Unit__c.Building__r.id IN :id];
    Building__c b;
    integer sum=0;
    for(Unit__c u: unit){
        sum= sum + Integer.valueOf(u.Add_Units__c);
        b =  [select id,Number_of_Units__c from Building__c where Id =: u.Building__c];
        b.Number_of_Units__c= sum;
    upsert b;
I am not getting the error.