• Vinothkumar M 1
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies
Hi all,

How to call already created Approval Process from batch apex .

Please any one guide to me.

Thanks
Hi all,

How to call approval process in Batch Apex Class.

any one help with me

Thanks
Hi ass,
Am new for Salesforce , Please any one help with write test class for following trigger class.

TRIGGER Handler

public class AccRatingandContactRoleTriggerHandler {
    
    public static void ContactRole(List<Opportunity> opty,List<Opportunity> opty1, Map<Id, Opportunity> oldMap){
        
    List<Id> oid = new List<ID>();
    for(Opportunity opp:opty1)
    {
        if(opp.StageName == 'Shaping' || opp.StageName =='Proposal Submitted' || opp.StageName =='Decision' || opp.StageName =='Won-Work In Progress' || opp.StageName =='Closed Won' || opp.StageName =='Delivered'){
            oid.add(opp.id);
        }
        
    }
    Map<Id, Opportunity> OppMap = OldMap;
    List<OpportunityContactRole> oppl = [select id, ContactId, Role, opportunityId from OpportunityContactRole 
                                      where opportunityId IN:oid];
            system.debug(oppl);
    for(opportunity opp1:opty)
    {
        if(oppl.isEmpty()){
        if(opp1.StageName =='Proposal Submitted' || opp1.StageName =='Decision' || opp1.StageName =='Won-Work In Progress' || opp1.StageName =='Closed Won' || opp1.StageName =='Delivered'){
                OppMap.get(opp1.id).addError('Error Message'));
           
        }
      
        }else{
            system.debug('success');
        }
    }
}
    
    Public static void AccRating(list<Opportunity> opp,Map<Id, Opportunity> a1){
        
       
        list<Id> accIds = new list<Id>();
        list<Account> accounts = new list<Account>();
    for(opportunity o:opp){
        if(o.StageName != a1.get(o.id).StageName){
            if(o.StageName =='Won-Work In Progress' || o.StageName =='Closed Won' || o.StageName =='Delivered'){
                accIds.add(o.accountId);
            }
        }
    }
    for(account a:[select Id, Rating from account where Id IN :accIds]){
        a.Rating='Client - Customer';
        accounts.add(a);
        AccRatingBecomeClient.sendingEmail();

   }
    
 update accounts; 
         
}
    public static void AccToOpty(list<Opportunity> oppy){
        list<Id> accIds = new list<Id>();  
        list<Account> accounts = new list<account>();
         List<Opportunity> opps = new List<Opportunity>(); 
    
          for(opportunity o:oppy){
        accIds.add(o.accountId);
          }
   
          for(account a:[select Id, Rating from account where Id IN :accIds]){
          for(opportunity opp:oppy){
            if(opp.StageName == 'Engagement' || opp.StageName =='Shaping' || opp.StageName =='Proposal Submitted' || opp.StageName =='Decision'){
                a.Rating='Prospect';
             accounts.add(a);
        }
    }
    } 
        update accounts;           
}  
    public static void AccOptyType(list<Opportunity> opy){
        
        
        set<id> setAccountownerIDs = new set<id>();
           //Map<id,User> usermap = new Map<id,User>();
        for (opportunity acc : opy)
           {
            setAccountownerIDs.add(acc.ownerID);
           } 
        List<opportunity> liop = new List<opportunity>();
        List<User> liusr = [select id,userrole.name from User where id IN: setAccountownerIDs];
           for(User u:liusr){
             for(opportunity opp : opy){
                    System.debug(opp);
                       if(opp.StageName == 'Engagement' || opp.StageName == 'Shaping' || opp.StageName =='Proposal Submitted' || opp.StageName =='Decision'){
                             System.debug(u.userrole.name);
                          if( u.userrole.name == 'Head of DELL' || u.userrole.name == 'IAD Team Members'){ 
                          opp.Opportunity_Type__c = 'DELL';
            
                    }
                       else if(u.userrole.name == 'Head of HP' || u.userrole.name == 'HP Team Members'){ 
                            opp.Opportunity_Type__c = 'HP';
                      }
           
                       else if( u.userrole.name == 'AMD Team Members' || u.userrole.name == 'AMD Head(CEO)'){ 
                            opp.Opportunity_Type__c = 'AMD';
                      }   
            
                        System.debug(opp.Opportunity_Type__c);
                }
               } 
          }     
        
      
    }
    
}

Test Class

@isTest
public class AccRatingandContactRoleTrigHandlerTest {

    public static testMethod void ContactRole(){
        
        Account acc = new Account();
            acc.Name ='New';
               acc.Rating='Prospect';
        insert acc;
       
       Contact con = new Contact();
               con.Salutation='Mr';
               con.LastName='Newcon';
               con.AccountId=acc.id;
       insert con;
            
        
        Opportunity opp = new Opportunity();
            opp.Name = 'New';
            opp.AccountId=acc.id;
            opp.StageName='Shaping';
               opp.Contact__c = con.id;
            opp.CloseDate=Date.Today();
            opp.Amount=100000;
        
        insert opp;
       
       OpportunityContactRole cr = new OpportunityContactRole();
               cr.ContactId = con.id;
               cr.Role = 'Decision Maker';
               cr.OpportunityId = opp.id;
       
       insert cr;
       
       try{
            opp.StageName = 'Won-Work In Progress';
               update opp;
       }catch(exception e){
                Boolean expectedExceptionThrown =  e.getMessage().contains('Error Message') ? true : false;
             System.AssertEquals(expectedExceptionThrown, true);
            
        }
        
    }  
    
    Public static testMethod void AccRating(){
        
         Account acc = new Account();
            acc.Name ='New';
            acc.Rating='Prospect';
                       
       insert acc;
              
        Contact con = new Contact();
               con.Salutation='Mr';
               con.LastName='New';
               con.AccountId=acc.id;
       
       insert con;
                   
        Opportunity opp = new Opportunity();
            opp.Name = 'New';
            opp.AccountId=acc.id;
            opp.StageName='Proposal Submitted';
               opp.Contact__c = con.id;
            opp.CloseDate=Date.Today();
            opp.Amount=100000;
                    
        insert opp;
       
        OpportunityContactRole cr = new OpportunityContactRole();
               cr.ContactId = con.id;
               cr.Role = 'Decision Maker';
               cr.OpportunityId = opp.id;
       
       insert cr;
        
        opp.StageName='Won-Work In Progress';
        
       update opp;
        
    }
    
    Public static testMethod void AccToOpty(){
        
         Account acc = new Account();
            acc.Name ='New';
            acc.Rating='Won-Work In Progress';
                       
       insert acc;
              
        Contact con = new Contact();
               con.Salutation='Mr';
               con.LastName='New';
               con.AccountId=acc.id;
       
       insert con;
        
                     
        Opportunity opp = new Opportunity();
            opp.Name = 'New';
            opp.AccountId=acc.id;
            opp.StageName='Closed Won';
               opp.Contact__c = con.id;
            opp.CloseDate=Date.Today();
            opp.Amount=100000;
                    
        insert opp;
       
        OpportunityContactRole cr = new OpportunityContactRole();
               cr.ContactId = con.id;
               cr.Role = 'Decision Maker';
               cr.OpportunityId = opp.id;
       
       insert cr;
        
        opp.StageName='Engagement';
        
        update opp;
        
    }
    
    public static testMethod void AccOptyType(){
        
        
         Account acc = new Account();
             acc.name='oppTest';
             acc.Rating='Client';
         insert acc;
        
         Opportunity opp = new Opportunity();
            opp.name='testtype1';
            opp.AccountId=acc.Id;
            opp.StageName='Engagement';
            opp.Amount = 1000000;
            opp.CloseDate= System.today();
            
         insert opp;
        
         Account acc1 = new Account();
             acc1.name='oppTest1';
             acc1.Rating='Client';
         insert acc1;
        
         Opportunity opp1 = new Opportunity();
            opp1.name='testtype2';
            opp1.AccountId=acc1.Id;
            opp1.StageName='Engagement';
            opp1.Amount = 1000000;
               opp1.CloseDate=  System.today();
            
        insert opp1;
        
        Account acc2 = new Account();
             acc2.name='oppTest2';
             acc2.Rating='Client';
        insert acc2;
        
        Opportunity opp2 = new Opportunity();
            opp2.name='testtype3';
            opp2.AccountId=acc2.Id;
            opp2.StageName='Engagement';
            opp2.Amount = 1000000;
            opp2.CloseDate=  System.today();
            
        insert opp2;
        
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
        User u = new User(Alias = 'standt', Email='testing@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='testing@testorg.com');
        
        insert u;
              
            opp.Opportunity_Type__c = 'Dell';
            opp1.Opportunity_Type__c = 'HP';
            opp2.Opportunity_Type__c = 'AMD';
                     
        update opp;
        update opp1;
        update opp2;
               
    }
}
HI all,

Account which don’t have opty for more than 2 years, all need to move to Lead.

please help with write batch apex

Any one please suggest 
Hi all,

How to call approval process in Batch Apex Class.

any one help with me

Thanks
Hi ass,
Am new for Salesforce , Please any one help with write test class for following trigger class.

TRIGGER Handler

public class AccRatingandContactRoleTriggerHandler {
    
    public static void ContactRole(List<Opportunity> opty,List<Opportunity> opty1, Map<Id, Opportunity> oldMap){
        
    List<Id> oid = new List<ID>();
    for(Opportunity opp:opty1)
    {
        if(opp.StageName == 'Shaping' || opp.StageName =='Proposal Submitted' || opp.StageName =='Decision' || opp.StageName =='Won-Work In Progress' || opp.StageName =='Closed Won' || opp.StageName =='Delivered'){
            oid.add(opp.id);
        }
        
    }
    Map<Id, Opportunity> OppMap = OldMap;
    List<OpportunityContactRole> oppl = [select id, ContactId, Role, opportunityId from OpportunityContactRole 
                                      where opportunityId IN:oid];
            system.debug(oppl);
    for(opportunity opp1:opty)
    {
        if(oppl.isEmpty()){
        if(opp1.StageName =='Proposal Submitted' || opp1.StageName =='Decision' || opp1.StageName =='Won-Work In Progress' || opp1.StageName =='Closed Won' || opp1.StageName =='Delivered'){
                OppMap.get(opp1.id).addError('Error Message'));
           
        }
      
        }else{
            system.debug('success');
        }
    }
}
    
    Public static void AccRating(list<Opportunity> opp,Map<Id, Opportunity> a1){
        
       
        list<Id> accIds = new list<Id>();
        list<Account> accounts = new list<Account>();
    for(opportunity o:opp){
        if(o.StageName != a1.get(o.id).StageName){
            if(o.StageName =='Won-Work In Progress' || o.StageName =='Closed Won' || o.StageName =='Delivered'){
                accIds.add(o.accountId);
            }
        }
    }
    for(account a:[select Id, Rating from account where Id IN :accIds]){
        a.Rating='Client - Customer';
        accounts.add(a);
        AccRatingBecomeClient.sendingEmail();

   }
    
 update accounts; 
         
}
    public static void AccToOpty(list<Opportunity> oppy){
        list<Id> accIds = new list<Id>();  
        list<Account> accounts = new list<account>();
         List<Opportunity> opps = new List<Opportunity>(); 
    
          for(opportunity o:oppy){
        accIds.add(o.accountId);
          }
   
          for(account a:[select Id, Rating from account where Id IN :accIds]){
          for(opportunity opp:oppy){
            if(opp.StageName == 'Engagement' || opp.StageName =='Shaping' || opp.StageName =='Proposal Submitted' || opp.StageName =='Decision'){
                a.Rating='Prospect';
             accounts.add(a);
        }
    }
    } 
        update accounts;           
}  
    public static void AccOptyType(list<Opportunity> opy){
        
        
        set<id> setAccountownerIDs = new set<id>();
           //Map<id,User> usermap = new Map<id,User>();
        for (opportunity acc : opy)
           {
            setAccountownerIDs.add(acc.ownerID);
           } 
        List<opportunity> liop = new List<opportunity>();
        List<User> liusr = [select id,userrole.name from User where id IN: setAccountownerIDs];
           for(User u:liusr){
             for(opportunity opp : opy){
                    System.debug(opp);
                       if(opp.StageName == 'Engagement' || opp.StageName == 'Shaping' || opp.StageName =='Proposal Submitted' || opp.StageName =='Decision'){
                             System.debug(u.userrole.name);
                          if( u.userrole.name == 'Head of DELL' || u.userrole.name == 'IAD Team Members'){ 
                          opp.Opportunity_Type__c = 'DELL';
            
                    }
                       else if(u.userrole.name == 'Head of HP' || u.userrole.name == 'HP Team Members'){ 
                            opp.Opportunity_Type__c = 'HP';
                      }
           
                       else if( u.userrole.name == 'AMD Team Members' || u.userrole.name == 'AMD Head(CEO)'){ 
                            opp.Opportunity_Type__c = 'AMD';
                      }   
            
                        System.debug(opp.Opportunity_Type__c);
                }
               } 
          }     
        
      
    }
    
}

Test Class

@isTest
public class AccRatingandContactRoleTrigHandlerTest {

    public static testMethod void ContactRole(){
        
        Account acc = new Account();
            acc.Name ='New';
               acc.Rating='Prospect';
        insert acc;
       
       Contact con = new Contact();
               con.Salutation='Mr';
               con.LastName='Newcon';
               con.AccountId=acc.id;
       insert con;
            
        
        Opportunity opp = new Opportunity();
            opp.Name = 'New';
            opp.AccountId=acc.id;
            opp.StageName='Shaping';
               opp.Contact__c = con.id;
            opp.CloseDate=Date.Today();
            opp.Amount=100000;
        
        insert opp;
       
       OpportunityContactRole cr = new OpportunityContactRole();
               cr.ContactId = con.id;
               cr.Role = 'Decision Maker';
               cr.OpportunityId = opp.id;
       
       insert cr;
       
       try{
            opp.StageName = 'Won-Work In Progress';
               update opp;
       }catch(exception e){
                Boolean expectedExceptionThrown =  e.getMessage().contains('Error Message') ? true : false;
             System.AssertEquals(expectedExceptionThrown, true);
            
        }
        
    }  
    
    Public static testMethod void AccRating(){
        
         Account acc = new Account();
            acc.Name ='New';
            acc.Rating='Prospect';
                       
       insert acc;
              
        Contact con = new Contact();
               con.Salutation='Mr';
               con.LastName='New';
               con.AccountId=acc.id;
       
       insert con;
                   
        Opportunity opp = new Opportunity();
            opp.Name = 'New';
            opp.AccountId=acc.id;
            opp.StageName='Proposal Submitted';
               opp.Contact__c = con.id;
            opp.CloseDate=Date.Today();
            opp.Amount=100000;
                    
        insert opp;
       
        OpportunityContactRole cr = new OpportunityContactRole();
               cr.ContactId = con.id;
               cr.Role = 'Decision Maker';
               cr.OpportunityId = opp.id;
       
       insert cr;
        
        opp.StageName='Won-Work In Progress';
        
       update opp;
        
    }
    
    Public static testMethod void AccToOpty(){
        
         Account acc = new Account();
            acc.Name ='New';
            acc.Rating='Won-Work In Progress';
                       
       insert acc;
              
        Contact con = new Contact();
               con.Salutation='Mr';
               con.LastName='New';
               con.AccountId=acc.id;
       
       insert con;
        
                     
        Opportunity opp = new Opportunity();
            opp.Name = 'New';
            opp.AccountId=acc.id;
            opp.StageName='Closed Won';
               opp.Contact__c = con.id;
            opp.CloseDate=Date.Today();
            opp.Amount=100000;
                    
        insert opp;
       
        OpportunityContactRole cr = new OpportunityContactRole();
               cr.ContactId = con.id;
               cr.Role = 'Decision Maker';
               cr.OpportunityId = opp.id;
       
       insert cr;
        
        opp.StageName='Engagement';
        
        update opp;
        
    }
    
    public static testMethod void AccOptyType(){
        
        
         Account acc = new Account();
             acc.name='oppTest';
             acc.Rating='Client';
         insert acc;
        
         Opportunity opp = new Opportunity();
            opp.name='testtype1';
            opp.AccountId=acc.Id;
            opp.StageName='Engagement';
            opp.Amount = 1000000;
            opp.CloseDate= System.today();
            
         insert opp;
        
         Account acc1 = new Account();
             acc1.name='oppTest1';
             acc1.Rating='Client';
         insert acc1;
        
         Opportunity opp1 = new Opportunity();
            opp1.name='testtype2';
            opp1.AccountId=acc1.Id;
            opp1.StageName='Engagement';
            opp1.Amount = 1000000;
               opp1.CloseDate=  System.today();
            
        insert opp1;
        
        Account acc2 = new Account();
             acc2.name='oppTest2';
             acc2.Rating='Client';
        insert acc2;
        
        Opportunity opp2 = new Opportunity();
            opp2.name='testtype3';
            opp2.AccountId=acc2.Id;
            opp2.StageName='Engagement';
            opp2.Amount = 1000000;
            opp2.CloseDate=  System.today();
            
        insert opp2;
        
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
        User u = new User(Alias = 'standt', Email='testing@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='testing@testorg.com');
        
        insert u;
              
            opp.Opportunity_Type__c = 'Dell';
            opp1.Opportunity_Type__c = 'HP';
            opp2.Opportunity_Type__c = 'AMD';
                     
        update opp;
        update opp1;
        update opp2;
               
    }
}
HI all,

Account which don’t have opty for more than 2 years, all need to move to Lead.

please help with write batch apex

Any one please suggest