• SFDC Ravi Kumar
  • NEWBIE
  • 0 Points
  • Member since 2016
  • Salesforce Developer
  • Aphidas

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hi Team,

I am updating the child status(FPA_Status__c) to parent status(Provider_Status__c).
EX: One Parent there are three child records, if any one of the record status is  Member or Ahp member I need to update parent status is ACTIVE otherwise InActive.
Below is the code working for one rec, Bulk rec not working Properlly
Error : Error: System.LimitException: Too many SOQL queries: 101

 
Public class ProviderStatusTriggerHandler{
    Public static void StatusUpdate(List<HealthcarePractitionerFacility> Hpfs){
    Map<ID,HealthcarePractitionerFacility> MapHPF = New Map<Id,HealthcarePractitionerFacility>();
    Set<Id> SetIds = New Set<Id>();
    Id RecordType = Schema.SObjectType.HealthcarePractitionerFacility.getRecordTypeInfosByName().get('Provider Location').getRecordTypeId();
    for(HealthcarePractitionerFacility HPF : Hpfs){
        if(HPF._FPA_Status__c != NULL && HPF.RecordtypeID == RecordType){
            MapHPF.Put(HPF.ID,HPF);
            SetIds.add(HPF.AccountId);
        }
    }    
      System.debug('@@@MapHPF'+MapHPF);
      
      
     List<Account> UpdateAccList = New List<Account>();
     List<HealthcarePractitionerFacility> FPAList = New List<HealthcarePractitionerFacility>([Select ID,Name,FPA_Status__c,AccountId from HealthcarePractitionerFacility where ID IN: MapHPF.Keyset()]);   
     
     System.debug('@@@FPAList'+FPAList.Size());
     
     List<HealthcarePractitionerFacility> NewList = New List<HealthcarePractitionerFacility>([Select ID,Name,FPA_Status__c,AccountId from HealthcarePractitionerFacility where AccountID IN: SetIds]);
     System.debug('@@@NewList'+NewList.Size());

         Map<String,HealthcarePractitionerFacility> NewMap = New Map<String,HealthcarePractitionerFacility>();
            for(HealthcarePractitionerFacility HPF : NewList){
                IF(HPF.FPA_Status__c != NULL){
                    NewMap.put(HPF.FPA_Status__c,HPF);
                }
            }
          System.debug('@@@NewMap'+NewMap.Size());
          System.debug('@@@NewMapRec'+NewMap);
      
     for(HealthcarePractitionerFacility HP : FPAList){
     for(Account a : [Select ID,Name,Provider_Status__c from Account where ID IN: SetIds]){
         If(MapHPF.containsKey(a.id) || HP.FPA_Status__c == 'Member'|| HP.FPA_Status__c == 'AHP Member' ){
             a.Provider_Status__c = 'Active';
             UpdateAccList.add(a);
             }
         
         else{
             if((!NewMap.containsKey('Member')) && (!NewMap.containsKey('AHP Member'))) {
                         
             a.Provider_Status__c = 'Inactive';
             UpdateAccList.add(a);
             }
           }
         }
        }
         if(UpdateAccList.size()>0){
            try{
                Update UpdateAccList;
               }catch(Exception e){
            System.debug('Exception occurred'+e.getMessage());
            }
        }
        System.debug('@@@UpdateAccList'+UpdateAccList);
        } 
    
}

 
1. Test Class
@isTest
public class DealerInfoControllerTest {
static testMethod void DealerInfoControllerTest() {
    
    Account acc = new Account();
    acc.Name = 'N28Team';
    insert acc;
    
    Contact con = new Contact();
    con.LastName = 'Testcon';
    con.email = 'pm@n28tech.com';
    insert con;
    
    opportunity opp = new opportunity();
    opp.name = 'Oppteamtest';
    opp.StageName = 'contract signed';
    opp.closedate = System.today();
    opp.stageName = 'Contract Signed';
    opp.Opportunity_Category__c = 'Ecommerce';
    opp.Submit_For_Approval__c = TRUE; 
    opp.accountid = acc.id;   
    insert opp;
    
    Customer__c cus = new Customer__c();
    cus.name = 'test customer';
    cus.Account_Name__c = Acc.id;
    cus.Opportunity_Name__c = opp.id;
    cus.Primary_Customer_Name__c =con.id;
    cus.CSM_Stage__c = 'On-boarding';
    insert cus;
    
    cus.Create_new_community_user__c = TRUE;
    cus.Is_Primary_Contact_a_Community_User__c = TRUE;
    cus.Send_Dealer_Info_Welcome_Email__c = TRUE;
    update cus;
    
    Dealer_Info__c Di = new Dealer_Info__c();
    Di.Name = 'NewDiForm';
    Di.Customer__c = cus.id;
    Di.Status__c = 'Dealer Info Form Started';
    Di.Account_Name__c = Acc.id;    
    insert Di;
        
    
    DealerInfoController DiFormObj = New DealerInfoController();
    //DiFormObj.getDealerinfo();

    
    }
}

2. Apex class
public without sharing class InfoController {
    @AuraEnabled
    public static Dealer_Info__c getDealerinfo(string recordId) {
        return [select Id, Name,Account_Name__c ,Customer__c,Status__c,General_Manager__c,BDC_Internet_Manager__c,Marketing_Manager__c,
                GM_Email2__c,BDC_Email__c,MM_Email__c,GM_Phone__c,BDC_Phone__c,MM_Phone__c,
                Primary_POC_for_Modal__c,GSM__c,Approver_for_install__c,Pricing_Manager__c,Finance_Manager__c,
                General_Manager__r.email,BDC_Internet_Manager__r.email,Marketing_Manager__r.email,
                Primary_POC_for_Modal__r.Email,GSM__r.Email,Approver_for_install__r.Email,Pricing_Manager__r.Email,Finance_Manager__r.Email,
                General_Manager__r.phone,BDC_Internet_Manager__r.phone,Marketing_Manager__r.phone,
                Primary_POC_for_Modal__r.phone,GSM__r.phone,Approver_for_install__r.phone,Pricing_Manager__r.phone,Finance_Manager__r.phone,
                Stock_or_VIN_Loan_New_Example2__c,POC_Email__c
                from Dealer_Info__c where Id=:recordId Limit 1];
    }
    @AuraEnabled
    public static Dealer_Info__c SaveDealerinfo(string GM,string BDC,string MM,string POC,string GSM,string approver,string FM,string PM,string recId) {
        Dealer_Info__c obJDealer =[select id,General_Manager__c from Dealer_Info__c where Id=:recId];
        if(string.isNotBlank(GM)){
          obJDealer.General_Manager__c= GM;
        }
        else{
            obJDealer.General_Manager__c= null;
        }
        if(string.isNotBlank(BDC)){
          obJDealer.BDC_Internet_Manager__c= BDC;
        }   
        else{
            obJDealer.BDC_Internet_Manager__c= null;
        }
        if(string.isNotBlank(MM)){
          obJDealer.Marketing_Manager__c= MM;
        }
        else{
            obJDealer.Marketing_Manager__c= null;
        }
        if(string.isNotBlank(POC)){
          obJDealer.Primary_POC_for_Modal__c= POC;
        }
        else{
            obJDealer.Primary_POC_for_Modal__c= null;
        }
        if(string.isNotBlank(GSM)){
          obJDealer.GSM__c= GSM;
        }
        else{
            obJDealer.GSM__c= null;
        }
        if(string.isNotBlank(approver)){
          obJDealer.Approver_for_install__c= approver;
        }
        else{
            obJDealer.Approver_for_install__c= null;
        }
        if(string.isNotBlank(FM)){
          obJDealer.Finance_Manager__c= FM;
        }
        else{
            obJDealer.Finance_Manager__c= null;
        }
        if(string.isNotBlank(PM)){
          obJDealer.Pricing_Manager__c= PM;
        }
        else{
            obJDealer.Pricing_Manager__c= null;
        }
        try{
            update obJDealer;
        }
        catch(Exception ex){
            system.debug('error while finish'+ex);
        }
        return obJDealer; 
    }
     @AuraEnabled
    public static Dealer_Info__c changeDealerStatus(string GM,string BDC,string MM,string POC,string GSM,string approver,string FM,string PM,string recId) {
        Dealer_Info__c obJDealer =[select id from Dealer_Info__c where Id=:recId];
        if(string.isNotBlank(GM)){
          obJDealer.General_Manager__c= GM;
        }
        if(string.isNotBlank(BDC)){
          obJDealer.BDC_Internet_Manager__c= BDC;
        }       
        if(string.isNotBlank(MM)){
          obJDealer.Marketing_Manager__c= MM;
        }
        if(string.isNotBlank(POC)){
          obJDealer.Primary_POC_for_Modal__c= POC;
        }
        if(string.isNotBlank(GSM)){
          obJDealer.GSM__c= GSM;
        }
        if(string.isNotBlank(approver)){
          obJDealer.Approver_for_install__c= approver;
        }
        if(string.isNotBlank(FM)){
          obJDealer.Finance_Manager__c= FM;
        }
        if(string.isNotBlank(PM)){
          obJDealer.Pricing_Manager__c= PM;
        }
        obJDealer.Status__c='Customer Form Completed';
        try{
            update obJDealer;
        }
        catch(Exception ex){
            system.debug('error while finish'+ex);
        }
        return obJDealer; 
    }
 
        
}

 
Hi Team,

I am updating the child status(FPA_Status__c) to parent status(Provider_Status__c).
EX: One Parent there are three child records, if any one of the record status is  Member or Ahp member I need to update parent status is ACTIVE otherwise InActive.
Below is the code working for one rec, Bulk rec not working Properlly
Error : Error: System.LimitException: Too many SOQL queries: 101

 
Public class ProviderStatusTriggerHandler{
    Public static void StatusUpdate(List<HealthcarePractitionerFacility> Hpfs){
    Map<ID,HealthcarePractitionerFacility> MapHPF = New Map<Id,HealthcarePractitionerFacility>();
    Set<Id> SetIds = New Set<Id>();
    Id RecordType = Schema.SObjectType.HealthcarePractitionerFacility.getRecordTypeInfosByName().get('Provider Location').getRecordTypeId();
    for(HealthcarePractitionerFacility HPF : Hpfs){
        if(HPF._FPA_Status__c != NULL && HPF.RecordtypeID == RecordType){
            MapHPF.Put(HPF.ID,HPF);
            SetIds.add(HPF.AccountId);
        }
    }    
      System.debug('@@@MapHPF'+MapHPF);
      
      
     List<Account> UpdateAccList = New List<Account>();
     List<HealthcarePractitionerFacility> FPAList = New List<HealthcarePractitionerFacility>([Select ID,Name,FPA_Status__c,AccountId from HealthcarePractitionerFacility where ID IN: MapHPF.Keyset()]);   
     
     System.debug('@@@FPAList'+FPAList.Size());
     
     List<HealthcarePractitionerFacility> NewList = New List<HealthcarePractitionerFacility>([Select ID,Name,FPA_Status__c,AccountId from HealthcarePractitionerFacility where AccountID IN: SetIds]);
     System.debug('@@@NewList'+NewList.Size());

         Map<String,HealthcarePractitionerFacility> NewMap = New Map<String,HealthcarePractitionerFacility>();
            for(HealthcarePractitionerFacility HPF : NewList){
                IF(HPF.FPA_Status__c != NULL){
                    NewMap.put(HPF.FPA_Status__c,HPF);
                }
            }
          System.debug('@@@NewMap'+NewMap.Size());
          System.debug('@@@NewMapRec'+NewMap);
      
     for(HealthcarePractitionerFacility HP : FPAList){
     for(Account a : [Select ID,Name,Provider_Status__c from Account where ID IN: SetIds]){
         If(MapHPF.containsKey(a.id) || HP.FPA_Status__c == 'Member'|| HP.FPA_Status__c == 'AHP Member' ){
             a.Provider_Status__c = 'Active';
             UpdateAccList.add(a);
             }
         
         else{
             if((!NewMap.containsKey('Member')) && (!NewMap.containsKey('AHP Member'))) {
                         
             a.Provider_Status__c = 'Inactive';
             UpdateAccList.add(a);
             }
           }
         }
        }
         if(UpdateAccList.size()>0){
            try{
                Update UpdateAccList;
               }catch(Exception e){
            System.debug('Exception occurred'+e.getMessage());
            }
        }
        System.debug('@@@UpdateAccList'+UpdateAccList);
        } 
    
}

 
Hi,
I have the contact object which has 2 fields-- job code and job grade.
I have another object job code where there are 2 fields job code and job grade.
When a user creates a contact and enters a job code, he should get the job grade populated automatically.
How can do this using a Map?
Thanks.
HI All

I have 3 object Contact,Boutique and Opportunity.All are relationship with each other.I need to auto opportunity record creation when boutique will be created .I have created this trigger but its showing in boutique layout .but i need in contact layout.
trigger CreateOpportunity on Boutique__c(after insert) {
    List<Opportunity> Childs = new List<Opportunity>();

    for(Boutique__c a : trigger.new)
    {
       Opportunity Child = new Opportunity();
       Child.Boutique__c= a.Customer_Name__c;
       Child.Name= a.Name;
        Child.StageName= 'Generate Opportunity';
         Child.CloseDate= System.Today()+150;
      
     
       Childs.add(Child);      
    }

    Insert Childs;
}
User-added image
 
How to Update the Case status to Closed using trigger When ClosedDate is Today.
can any one help me.
Thanks in advance