• srikanth cheera 6
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 10
    Replies
/* Write a batch apex to fetch all the tasks assigned to the user and set the status as closed with test class.*/

global class Task19 implements database.Batchable<sobject>{

    global database.QueryLocator start(database.BatchableContext bc){
        return database.getQueryLocator('select id,name,status from task');
    }
    global void execute(database.BatchableContext bc,list<Task> ta){
        user u=[select id from user where alias='sec'];
        for(Task t:ta){
            t.status='closed';
            t.id=u.id;
        }
        update ta;
    }
    global void finish(database.BatchableContext bc){
        
    }
    
}
global class Task020 implements database.Batchable<sobject>{
 
    global database.QueryLocator start(database.BatchableContext bc){
        return database.getQueryLocator('select id,name from Account where createddate= Today()');
    }
    global void execute(database.BatchableContext bc,list<Account> acc){
        for(Account a:acc){
            }
        delete acc;
        }
        
        global void finish(database.BatchableContext bc){
            
        }
    }
public class Task14 {
 
    public static void beforeupdate(Map<id,Account> oldmap,Map<id,Account> newmap){
        list<id> accid=new list<id>();
        for(id key:oldmap.keySet()){
            Account old=oldmap.get(key);
            Account newmp=newmap.get(key);
            if(old.Phone!=newmp.Phone){
              accid.add(key);
            }
        }
        list<Contact> con=[select lastname,firstname,phone,accountid from Contact where accountid in:accid];
        for(Contact c:con){
            Account a=newmap.get(c.accountid);
            Account b=oldmap.get(c.accountid);
            c.Phone=a.Phone;
            c.OtherPhone=b.phone;
            
        }
        update con;
    }
}
==========================================================

trigger Task14Trigger on Account (before update) {
    if(trigger.isbefore && trigger.isupdate){
        Task14.beforeupdate(Trigger.oldmap, Trigger.newmap);
    }
}
====================================================================
Any one can write test code for this 
=============================
public class Task04{
public static void beforeinsert(list<Opportunity> opo){
for(Opportunity op:opo){
if(op.name!=null){
op.stagename='prospecting';
op.closedate=system.today()+15;
}
}
}
}
====
Thanks
/* Write a batch apex to fetch all the tasks assigned to the user and set the status as closed with test class.*/

global class Task19 implements database.Batchable<sobject>{

    global database.QueryLocator start(database.BatchableContext bc){
        return database.getQueryLocator('select id,name,status from task');
    }
    global void execute(database.BatchableContext bc,list<Task> ta){
        user u=[select id from user where alias='sec'];
        for(Task t:ta){
            t.status='closed';
            t.id=u.id;
        }
        update ta;
    }
    global void finish(database.BatchableContext bc){
        
    }
    
}
global class Task020 implements database.Batchable<sobject>{
 
    global database.QueryLocator start(database.BatchableContext bc){
        return database.getQueryLocator('select id,name from Account where createddate= Today()');
    }
    global void execute(database.BatchableContext bc,list<Account> acc){
        for(Account a:acc){
            }
        delete acc;
        }
        
        global void finish(database.BatchableContext bc){
            
        }
    }
public class Task14 {
 
    public static void beforeupdate(Map<id,Account> oldmap,Map<id,Account> newmap){
        list<id> accid=new list<id>();
        for(id key:oldmap.keySet()){
            Account old=oldmap.get(key);
            Account newmp=newmap.get(key);
            if(old.Phone!=newmp.Phone){
              accid.add(key);
            }
        }
        list<Contact> con=[select lastname,firstname,phone,accountid from Contact where accountid in:accid];
        for(Contact c:con){
            Account a=newmap.get(c.accountid);
            Account b=oldmap.get(c.accountid);
            c.Phone=a.Phone;
            c.OtherPhone=b.phone;
            
        }
        update con;
    }
}
==========================================================

trigger Task14Trigger on Account (before update) {
    if(trigger.isbefore && trigger.isupdate){
        Task14.beforeupdate(Trigger.oldmap, Trigger.newmap);
    }
}
====================================================================
Any one can write test code for this 
=============================
public class Task04{
public static void beforeinsert(list<Opportunity> opo){
for(Opportunity op:opo){
if(op.name!=null){
op.stagename='prospecting';
op.closedate=system.today()+15;
}
}
}
}
====
Thanks
Hi all,

Delete records batch apex account ,contacts ,opportunity and cases in single batchclass