• rahul Shukla 37
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 9
    Replies
Below is my code
public class ApplicantController {
    public List<ApplicantDataWrapper> applicantData { get; set; }
    
    public ApplicantController() {
        String fieldLabel;
        applicantData = new List<ApplicantDataWrapper>();
        
        // Query the custom metadata records for field mapping
        List<FieldMapping__mdt> fieldMappings = [SELECT Object_API_Name__c, Field_API_Name__c, Relationship_Field__c, Lookup_API_Name__c, label FROM FieldMapping__mdt WHERE Object_API_Name__c = 'Co_Applicant__c'];
        
        // Get the API names of the fields to query dynamically
        Set<String> fieldAPINames = new Set<String>();
        for (FieldMapping__mdt fieldMapping : fieldMappings) {
            if (fieldMapping.Object_API_Name__c == 'Co_Applicant__c') {
                fieldAPINames.add(fieldMapping.Field_API_Name__c);
                System.debug('fieldAPINames adding' + fieldAPINames);
            }
        }
        
        // Build the dynamic SOQL query
        String dynamicQuery = 'SELECT Id';
        for (String fieldAPIName : fieldAPINames) {
            dynamicQuery += ', ' + fieldAPIName;
            System.debug('dynamicQuery adding' + dynamicQuery);
        }
        dynamicQuery += ' FROM Co_Applicant__c LIMIT 1';
        System.debug('dynamicQuery' + dynamicQuery);
        
        // Query the Applicant object dynamically
        List<SObject> applicants = Database.query(dynamicQuery);
        if (!applicants.isEmpty()) {
            Co_Applicant__c applicant = (Co_Applicant__c)applicants[0];
            System.debug('applicantd ' + applicant);
            
            // Iterate over the field mappings and retrieve the label and value dynamically
            for (FieldMapping__mdt fieldMapping : fieldMappings) {
                String objectAPIName = fieldMapping.Object_API_Name__c;
                String fieldAPIName = fieldMapping.Field_API_Name__c;
                String fieldValue;
                
                if (objectAPIName == 'Co_Applicant__c') {
                    // Retrieve the label dynamically from the custom metadata records based on the field API name
                    if (!fieldMapping.Relationship_Field__c) {
                        fieldLabel = Schema.getGlobalDescribe().get(objectAPIName).getDescribe().fields.getMap().get(fieldAPIName).getDescribe().getLabel();
                        fieldValue = (applicant != null) ? String.valueOf(applicant.get(fieldAPIName)) : '';
                    } else {
                        // Handle lookup field value
                        String lookupFieldAPIName = fieldMapping.Lookup_API_Name__c;
                        fieldValue = (applicant != null) ? getLookupFieldValue(lookupFieldAPIName, applicant) : '';
                    }
                    
                    // Map field label with value
                    ApplicantDataWrapper dataWrapper = new ApplicantDataWrapper();
                    dataWrapper.fieldLabel = fieldLabel;
                    dataWrapper.fieldValue = fieldValue;
                    
                    // Add the data to the list
                    applicantData.add(dataWrapper);
                    System.debug('applicantData: ' + applicantData);
                }
            }
        }
    }
    
    // Method to fetch lookup field value using the --r notation from metadata
       public String getLookupFieldValue(String lookupFieldAPIName, Co_Applicant__c applicant) {
        if (applicant != null && applicant.get(lookupFieldAPIName) != null) {
            String lookupObjectName = lookupFieldAPIName.substringBefore('.');
            String lookupFieldName = lookupFieldAPIName.substringAfter('.');
            System.debug('lookupObjectName: ' + lookupObjectName);
            System.debug('lookupFieldName: ' + lookupFieldName);
            
            // Query the lookup object dynamically
            String query = 'SELECT ' + lookupFieldName + ' FROM ' + lookupObjectName +
                           ' WHERE Id = \'' + applicant.get(lookupFieldAPIName) + '\' LIMIT 1';
            List<SObject> lookupObjects = Database.query(query);
            
           
            
            if (!lookupObjects.isEmpty()) {
                SObject lookupObject = lookupObjects[0];
                if (lookupObject != null) {
                    return String.valueOf(lookupObject.get(lookupFieldName));
                }
            }
        }
        
        return '';
    }
    
    public class ApplicantDataWrapper {
        public String fieldLabel { get; set; }
        public String fieldValue { get; set; }
    }
}
I want to get the value of lead__r.Name from Co_Applicant__c Object
How to Logged all Email sent through salesforce on Activity timeline
Please help me to acheive this Scenario
If Response Time > Expected Time - 10 mins: Yellow I just wants to convert this in Formula as per GST Time
I have two record types on account object (household and organisation) once we convert the lead it's creates two accounts but both have same record type household only I want one will be household and another one will be organisation.

Please help me to achieve this scenario
I am getting the Null pointer error while keeping Lat invoice generated field blank.
Below is my code:
public class OpportunityTriggerEventHelper {
    
    public static void updateBaseRateOnOpp(Map<Id, Opportunity> oldDRObjMap, List<Opportunity> newDRObjList) {
        //if(checkRecursive.runOnce()){
            
            set<string> frequency = new set<string>();
            set<string> category = new set<String>();
            Set<Id> oppId = new Set<Id>();
            Map<string,Daily_Rate__c> maprate = new Map<string,Daily_Rate__c>(); 
            
            for(Opportunity d : newDRObjList){
                
                if(oldDRObjMap != null && oldDRObjMap.get(d.Id).cfg_LastInvGenDate__c !=d.cfg_LastInvGenDate__c) {
                    category.add(d.cfg_ChildAgeCat__c);
                    
                        oppId.add(d.Id);
                    }
                     }
            
            for(Opportunity opp : [SELECT Id, cfg_Enrollment__r.cfg_Attendance_Frequency__c FROM Opportunity WHERE ID IN :oppId]){
                frequency.add(opp.cfg_Enrollment__r.cfg_Attendance_Frequency__c);
            }
          
            list<Opportunity> oppLst = new list<Opportunity>();
            
            for(Opportunity opp : [SELECT Id, cfg_Enrollment__r.cfg_Attendance_Frequency__c, cfg_ChildAgeCat__c, cfg_LastInvGenDate__c FROM Opportunity WHERE ID IN :oppId]){
                
                for(Daily_Rate__c drObj : [SELECT Id, Attendance_frequency__c, Child_Category__c, Rate__c, Start_Date__c, End_Date__c 
                                           FROM Daily_Rate__c 
                                           WHERE Attendance_frequency__c = :opp.cfg_Enrollment__r.cfg_Attendance_Frequency__c AND Child_Category__c = :opp.cfg_ChildAgeCat__c
                                           AND Start_Date__c <= :opp.cfg_LastInvGenDate__c.addDays(7) AND End_Date__c >= :opp.cfg_LastInvGenDate__c.addDays(7)]){
                                               maprate.put(drObj.Attendance_frequency__c +''+drObj.Child_Category__c, drObj);   
                                           }
            }
            
            
            for(Opportunity opp : [SELECT Id, cfg_Enrollment__r.cfg_Attendance_Frequency__c, cfg_ChildAgeCat__c, cfg_LastInvGenDate__c FROM Opportunity WHERE ID IN :oppId]){
                if(maprate.containsKey(opp.cfg_Enrollment__r.cfg_Attendance_Frequency__c +''+ opp.cfg_ChildAgeCat__c)){
                    
                    if(maprate.get(opp.cfg_Enrollment__r.cfg_Attendance_Frequency__c +''+ opp.cfg_ChildAgeCat__c).Start_Date__c <= opp.cfg_LastInvGenDate__c.addDays(7) && maprate.get(opp.cfg_Enrollment__r.cfg_Attendance_Frequency__c +''+ opp.cfg_ChildAgeCat__c).End_Date__c >= opp.cfg_LastInvGenDate__c.addDays(7))
                        
                        opp.Base_Rate__c = maprate.get(opp.cfg_Enrollment__r.cfg_Attendance_Frequency__c +''+ opp.cfg_ChildAgeCat__c).Rate__c;
                       
                     
                        }
                oppLst.add(opp);
            }
            
            if(!oppLst.isEmpty()){
                update oppLst;    
            }
            
        //}
    }
}
public class cfg_LeadUtility {
     @InvocableMethod(label='Convert the Lead' description='Convert the lead by LeadId and returns True/False as success/failures' category='Lead')
    public static List<String> ConvertLead(List<ID> leadIds) {
        List<String> convertedLeads= new List<String>();
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        for (String leadId: leadIds) {
            Database.LeadConvert lc = new Database.LeadConvert();
            lc.setLeadId(leadId);
            lc.setConvertedStatus(convertStatus.MasterLabel);   
                    
            Database.LeadConvertResult lcr ;
            try{
                lcr = Database.convertLead(lc);
                system.debug('*****lcr.isSuccess()'+lcr.isSuccess());            
                convertedLeads.add(LeadId);
            }
            catch(exception ex){
                system.debug('***LEAD NOT CONVERTED**');           
            }
        }
        
        return convertedLeads;
    }   
}
i wants to test this class as per below Test class but not covering the code please anyone help me to find the issue in Test class
@isTest  
private class cfg_LeadUtilityTest {  
      
    static testMethod void testLeadConv() {  
          
        //Lead objLead = new Lead( FirstName = 'Test', LastName = 'Sample', Company = 'Testing Sample Co' );  
        Lead objLead = utilityHelperTest.createLead();
        insert objLead;  
          
        Database.LeadConvert lc = new database.LeadConvert();  
        lc.setLeadId( objLead.Id );  
        //lc.setDoNotCreateOpportunity( true );  
        lc.setConvertedStatus( 'Closed - Converted' );  
          
        Database.LeadConvertResult lcr = Database.convertLead(lc, false);  
          
        system.debug( 'Errors are ' + lcr.getErrors() );  
          
        system.assert( lcr.isSuccess() );  
          
    }  
  
}
 
Hi All,

I have one custom object daily rates, in which i am having one field rates and one picklist field is category(which include infant toddler and 3+), another object i have contact which also have three checkbox field (infant, toddler and 3+), if any of checkbox become true on contact, then i want to update base_rate field on opportunity and rate should fetch from the daily rate object, that i already set based on category (infant,toddler and 3+).
Please help me how can i achieve this scenerio.  
I wants to put filter on calendar,I have one custom field center_location(Picklist) on the basis of center location wants to put the filter on calendar so that once i select the any center_location calendar will show those meetings only. 
can anyone help me to achieve it.
I have multi select picklist in which I want values in available box should be default present in chosen box please help me to achieve this scenario.
Hi Everyone,
Please help me to achieve scenario 
when i will change the opportunity stage to confirm then i need one pop up the will show 2 button confirm and cancel.

 
I have one custom object in which two field is available available start date and previous enroll if previous enroll is not null then Available start date will be read only if null then it should be editable please help me to achieve this scenario
How write a trigger for opportunity stage cannot be move backward like if set 'qualification' not move to previous stage 'Prospecting'
Please help me on this question of SOQL
Find the account Specific account and check the number of contact associated with that account if the count of contact is odd add one more and make it even
I have multi select picklist in which I want values in available box should be default present in chosen box please help me to achieve this scenario.
Hi Everyone,
Please help me to achieve scenario 
when i will change the opportunity stage to confirm then i need one pop up the will show 2 button confirm and cancel.

 
How write a trigger for opportunity stage cannot be move backward like if set 'qualification' not move to previous stage 'Prospecting'
I am preparing for salesforce developer I certification and ran into a question:
 
A Developer wants to create a custom object to track Customer Invoices.
How should Invoices and Accounts be related to relate that all invoices are visible to everyone with access to the Account?
Of course it’s going to be a master detail relationship
There are two options:
The Invoice should have master detail relationship to the Account
 The Account should have master detail relationship to the Invoice.I want to know what is the difference between the two. They both look similar.
Can someone please help