• Priya Mukherjee 13
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
My code goes like this..


//******** Service Contract *******// 

public class ServiceContractTriggerHelper {
    
    public static void updateAddress(List<ServiceContract> src){
        
        Set<ID> acclist = new Set<ID>();
        
        Id rectype = Schema.SObjectType.ServiceContract.getRecordTypeInfosByName().get('Medical Alert Service').getRecordTypeId();
        
        for(ServiceContract sc: src){
            acclist.add(sc.AccountId);
        }
        
        Map<Id,Account> peronAccountList1 = new Map<Id, Account>();
        List<Account> aclst =  [Select Id,Is_Active_Shipping_Address__c,Is_Active_Alternate_Address__c,Alternate_City__c,Alternate_Country__c,
                                Township_Borough_Municipality_B__c,Township_Borough_Municipality_S__c FROM Account WHERE Id IN :acclist];
                                
        for(Integer i=0; i<aclst.size(); i++){
            peronAccountList1.put(aclst[i].id,aclst[i]);
        }
        for(ServiceContract sc: src){
            Account ac=peronAccountList1.get(sc.AccountId);
            if(accIdwithlist.get(sc.AccountId)!=null && sc.RecordType = rectype){
                if(ac.Is_Active_Shipping_Address__c){
                    sc.City__c = ac.Alternate_City__c;
                    sc.Country__c = ac.Alternate_Country__c;
                    sc.Township_Borough_Municipality__c = ac.Township_Borough_Municipality_S__c;
                }
                
                if(ac.Is_Active_Alternate_Address__c){
                    sc.City__c = ac.Alternate_City__c;
                    sc.Country__c = ac.Alternate_Country__c;
                    sc.Township_Borough_Municipality__c = ac.Township_Borough_Municipality_S__c;
                }
            }
            
        }
    }

}