• fiona gentry
  • NEWBIE
  • 180 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 29
    Questions
  • 13
    Replies
Hi Gurus,

I am trying to replicate the below functionality of Custom Dependent Picklist Field With lightning: select In Lightning Component for Custom Object (Ref:-Source (https://sfdcmonkey.com/2018/08/31/dependent-picklist-lightningselect-lightning-salesforce/)),

Only difference here is i am using Custom object `ERT_Case_Type_Data__c` and its 2 picklist `Level_1__c` and `Level_2__c` instead of standard object `Contact` reference in the article


Below are ERT_Case_Type_Data__c Object and data details
User-added imageUser-added image

Here is TestApp which uses this component, Unfortunately, I don't see data in the dropdown Picklist
Please help me in knowing what is wrong I am doing here


Here is Apex class dependentPicklist_UpdateCtrl.apxc
 
public class dependentPicklist_UpdateCtrl {
					@AuraEnabled 
					public static Map<String, List<String>> getDependentMap(sObject objDetail, string contrfieldApiName,string depfieldApiName) {
						String controllingField = contrfieldApiName.toLowerCase();
						String dependentField = depfieldApiName.toLowerCase();
						
						Map<String,List<String>> objResults = new Map<String,List<String>>();
						
						Schema.sObjectType objType = objDetail.getSObjectType();
						if (objType==null){
							return objResults;
						}
						
						Map<String, Schema.SObjectField> objFieldMap = objType.getDescribe().fields.getMap();
						
						if (!objFieldMap.containsKey(controllingField) || !objFieldMap.containsKey(dependentField)){
							return objResults;     
						}
						
						Schema.SObjectField theField = objFieldMap.get(dependentField);
						Schema.SObjectField ctrlField = objFieldMap.get(controllingField);
						
						List<Schema.PicklistEntry> contrEntries = ctrlField.getDescribe().getPicklistValues();
						List<PicklistEntryWrapper> depEntries = wrapPicklistEntries(theField.getDescribe().getPicklistValues());
						List<String> controllingValues = new List<String>();
						
						for (Schema.PicklistEntry ple : contrEntries) {
							String label = ple.getLabel();
							objResults.put(label, new List<String>());
							controllingValues.add(label);
						}
						
						for (PicklistEntryWrapper plew : depEntries) {
							String label = plew.label;
							String validForBits = base64ToBits(plew.validFor);
							for (Integer i = 0; i < validForBits.length(); i++) {
								String bit = validForBits.mid(i, 1);
								if (bit == '1') {
									objResults.get(controllingValues.get(i)).add(label);
								}
							}
						}
						return objResults;
					}
					
					public static String decimalToBinary(Integer val) {
						String bits = '';
						while (val > 0) {
							Integer remainder = Math.mod(val, 2);
							val = Integer.valueOf(Math.floor(val / 2));
							bits = String.valueOf(remainder) + bits;
						}
						return bits;
					}
					
					public static String base64ToBits(String validFor) {
						if (String.isEmpty(validFor)) return '';
						
						String validForBits = '';
						
						for (Integer i = 0; i < validFor.length(); i++) {
							String thisChar = validFor.mid(i, 1);
							Integer val = base64Chars.indexOf(thisChar);
							String bits = decimalToBinary(val).leftPad(6, '0');
							validForBits += bits;
						}
						
						return validForBits;
					}
					
					private static final String base64Chars = '' +
						'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
						'abcdefghijklmnopqrstuvwxyz' +
						'0123456789+/';
					
					
					private static List<PicklistEntryWrapper> wrapPicklistEntries(List<Schema.PicklistEntry> PLEs) {
						return (List<PicklistEntryWrapper>)
							JSON.deserialize(JSON.serialize(PLEs), List<PicklistEntryWrapper>.class);
					}
					
					public class PicklistEntryWrapper{
						public String active {get;set;}
						public String defaultValue {get;set;}
						public String label {get;set;}
						public String value {get;set;}
						public String validFor {get;set;}
						public PicklistEntryWrapper(){            
						}
						
					}
				}

Here is Component code dependentPicklist_UpdateCtrl.cmp
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
								access="global"
								controller="dependentPicklist_UpdateCtrl">
					<!-- call doInit function on component load -->  
					<aura:handler name="init" value="this" action="{!c.doInit}"/>
					
					<!-- aura attributes-->  
					<aura:attribute name="listControllingValues" type="list" default="[]" description="to store controller field values"/>
					<aura:attribute name="listDependingValues" type="list" default="['--- None ---']" description="to store dependent field values"/>
					<aura:attribute name="depnedentFieldMap" type="map" description="map to store dependent values with controlling value"/>
					<aura:attribute name="bDisabledDependentFld" type="boolean" default="true"/> 
					
					<aura:attribute name="objDetail" type="ERT_Case_Type_Data__c" default="{'sobjectType' : 'ERT_Case_Type_Data__c'}"/>
					<aura:attribute name="controllingFieldAPI" type="string" default="Level_1__c" description="store field API name of Controller field"/>
					<aura:attribute name="dependingFieldAPI" type="string" default="Level_2__c" description="store field API name of dependent field"/>
					
					<!--Controller Field-->
					<lightning:layoutItem size="12" padding="around-small">    
						<lightning:select name="controllerFld"
										  value="{!v.objDetail.Level_1__c}"
										  label="Level1"
										  onchange="{!c.onControllerFieldChange}">
							<aura:iteration items="{!v.listControllingValues}" var="val">
								<option value="{!val}">{!val}</option>
							</aura:iteration>
						</lightning:select>
					</lightning:layoutItem>
					
					<!--Dependent Field-->
					<lightning:layoutItem size="12" padding="around-small">
						<lightning:select name="dependentFld"
										  value="{!v.objDetail.Level_2__c}"
										  label="Level2"
										  >
							<aura:iteration items="{!v.listDependingValues}" var="val">
								<option value="{!val}">{!val}</option>
							</aura:iteration>
						</lightning:select>
					</lightning:layoutItem>
					
				</aura:component>


Here is Controller code for dependentPicklist_UpdateCtrlController.js
 
({
					doInit : function(component, event, helper) { 
						// get the fields API name and pass it to helper function  
						var controllingFieldAPI = component.get("v.controllingFieldAPI");
						var dependingFieldAPI = component.get("v.dependingFieldAPI");
						var objDetails = component.get("v.objDetail");
						// call the helper function
						helper.fetchPicklistValues(component,objDetails,controllingFieldAPI, dependingFieldAPI);
					},
					
					onControllerFieldChange: function(component, event, helper) {     
						var controllerValueKey = event.getSource().get("v.value"); // get selected controller field value
						var depnedentFieldMap = component.get("v.depnedentFieldMap");
						
						if (controllerValueKey != '--- None ---') {
							var ListOfDependentFields = depnedentFieldMap[controllerValueKey];
							
							if(ListOfDependentFields.length > 0){
								component.set("v.bDisabledDependentFld" , false);  
								helper.fetchDepValues(component, ListOfDependentFields);    
							}else{
								component.set("v.bDisabledDependentFld" , true); 
								component.set("v.listDependingValues", ['--- None ---']);
							}  
							
						} else {
							component.set("v.listDependingValues", ['--- None ---']);
							component.set("v.bDisabledDependentFld" , true);
						}
					},
				})

Here is Helper code for dependentPicklist_UpdateCtrlControllerHelper.js
 
({
					fetchPicklistValues: function(component,objDetails,controllerField, dependentField) {
						// call the server side function  
						var action = component.get("c.getDependentMap");
						// pass paramerters [object definition , contrller field name ,dependent field name] -
						// to server side function 
						action.setParams({
							'objDetail' : objDetails,
							'contrfieldApiName': controllerField,
							'depfieldApiName': dependentField 
						});
						//set callback   
						action.setCallback(this, function(response) {
							if (response.getState() == "SUCCESS") {
								//store the return response from server (map<string,List<string>>)  
								var StoreResponse = response.getReturnValue();
								
								// once set #StoreResponse to depnedentFieldMap attribute 
								component.set("v.depnedentFieldMap",StoreResponse);
								
								// create a empty array for store map keys(@@--->which is controller picklist values) 
								var listOfkeys = []; // for store all map keys (controller picklist values)
								var ControllerField = []; // for store controller picklist value to set on lightning:select. 
								
								// play a for loop on Return map 
								// and fill the all map key on listOfkeys variable.
								for (var singlekey in StoreResponse) {
									listOfkeys.push(singlekey);
								}
								
								//set the controller field value for lightning:select
								if (listOfkeys != undefined && listOfkeys.length > 0) {
									ControllerField.push('--- None ---');
								}
								
								for (var i = 0; i < listOfkeys.length; i++) {
									ControllerField.push(listOfkeys[i]);
								}  
								// set the ControllerField variable values to country(controller picklist field)
								component.set("v.listControllingValues", ControllerField);
							}else{
								alert('Something went wrong..');
							}
						});
						$A.enqueueAction(action);
					},
					
					fetchDepValues: function(component, ListOfDependentFields) {
						// create a empty array var for store dependent picklist values for controller field  
						var dependentFields = [];
						dependentFields.push('--- None ---');
						for (var i = 0; i < ListOfDependentFields.length; i++) {
							dependentFields.push(ListOfDependentFields[i]);
						}
						// set the dependentFields variable values to store(dependent picklist field) on lightning:select
						component.set("v.listDependingValues", dependentFields);
						
					},
					
				})

Please help me in identifying why data not displayed in Picklist dropdown only difference here is that its an Custom object with dependent Picklist

Regards,
​​​​​​​Fiona
 
Hi Gurus,

Step1--> I have a scenario where, in my dependent picklist, first i am setting values for  picklist Level2 and then selected dependent picklist value in Level3
User-added image

Step2--> Now this time removed selection at Level2 ,automatically Level3 selection also got erased and 

User-added image

Step3--> Click Save

User-added image

Here is problem,that value selected in Step2 getting saved rather than the reset value in step3

I have added code to reset values at 
ui:inputSelectOption
but it seems the reset  values from lightning components are not getting reset and saved rather cached values are getting saved after I click save,

Please help in fixing the code, here is the component code
<aura:component controller="PickListHandler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
					<!-- Actions-->
					<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
					<aura:handler name="change" value="{!v.pageReference}"
								  action="{!c.onPageReferenceChanged}" />
					<!-- variable-->
					<aura:attribute name="lstLevel1" type="String[]" />
					 <aura:attribute name="lstLevel2" type="String[]" />
					  <aura:attribute name="lstL3" type="String[]" />
					<span> Level 1</span>
					<ui:inputSelect aura:id="ddLevel1" change="{!c.getLvl1}">
						<ui:inputSelectOption label="-Select-" value="true"/>        
						<aura:iteration items="{!v.lstLevel1}" var="value">          
							<ui:inputSelectOption label="{!value}" text="{!value}" />
						</aura:iteration>
					</ui:inputSelect>
					<span>Level 2</span>
					<ui:inputSelect aura:id="ddLevel2"  change="{!c.getSelectedValue}">
						 <ui:inputSelectOption label="-Select-" value="{!v.clrlv1}"/>        
						<aura:iteration items="{!v.lstLevel2}" var="value">          
							<ui:inputSelectOption label="{!value}" text="{!value}" />
						</aura:iteration>
					</ui:inputSelect>
					 <span>Level 3</span>
					<ui:inputSelect aura:id="ddLevel3" >
						<ui:inputSelectOption label="-Select-" value="{!v.clrlv2}"/>        
						<aura:iteration items="{!v.lstL3}" var="value">          
							<ui:inputSelectOption label="{!value}" text="{!value}" />
						</aura:iteration>
					</ui:inputSelect>
				   <lightning:button variant="brand" label="Save" onclick="{!c.onConfirm}" />
				</aura:component>

here is controller  code
({
					   reset1 : function(component, event, helper) {
							component.set("v.clrlvl", "");
						},
						reset2 : function(component, event, helper) {
							component.set("v.clrlv2", "");
						},onPageReferenceChanged: function(cmp, event, helper) {
							$A.get('e.force:refreshView').fire();
						},
						doInit : function(component, event, helper) {
							var action = component.get("c.getLevel1");
							action.setCallback(this, function(e) {
								if(e.getState()=='SUCCESS'){
									var result=e.getReturnValue();
									component.set("v.lstLevel1",result);
								}
							});
							$A.enqueueAction(action);
						},    
						getLvl1:function(component, event, helper){
						   
							var picklist=component.find('ddLevel1');
							var picklistvalue=picklist.get('v.value');
							var action = component.get("c.getLevel2");
							action.setParams({  'strName' : picklistvalue  });
							action.setCallback(this, function(e) {
								if(e.getState()=='SUCCESS'){
									var result=e.getReturnValue();
									component.set("v.lstLevel2",result);
								}
							});
							$A.enqueueAction(action);
								},
						getSelectedValue:function(component, event, helper){
							var picklist=component.find('ddLevel1');
							var picklistvalue=picklist.get('v.value');
							var picklistdep=component.find('ddLevel2');
							var picklistvaluedep2=picklistdep.get('v.value');
							var action = component.get("c.getLevel3");
							action.setParams({  'strName1' : picklistvalue,
											 'strName2' : picklistvaluedep2});//
							action.setCallback(this, function(e) {
								if(e.getState()=='SUCCESS'){
									var result=e.getReturnValue();
									component.set("v.lstL3",result);
								}
							});
							$A.enqueueAction(action);
						},
						onConfirm:function(component, event, helper){
							var picklist=component.find('ddLevel1');
							var picklistvalue=picklist.get('v.value');
							var picklistdep=component.find('ddLevel2');
							var picklistvaluedep2=picklistdep.get('v.value');
						   
							var picklistdep3=component.find('ddLevel3');
							var picklistvaluedep3=picklistdep3.get('v.value');
							var action = component.get("c.savecasetype");
							
							action.setParams({  'level1' : picklistvalue,
											  'level2' : picklistvaluedep2,
											  'level3' : picklistvaluedep3,
											  'id' : component.get("v.recordId")});
											  
							
							var toastEvent = $A.get("e.force:showToast");
							action.setCallback(this, function(e) {
								if(e.getState()=='SUCCESS'){
									var result=e.getReturnValue();
									if(result==='successfull'){
										toastEvent.setParams({
											"title": "Success!",
											"message": "The record has been inserted  successfully."
										});
										toastEvent.fire();
									}else{
										toastEvent.setParams({
											"title": "Error",
											"message": "The record has not been inserted  successfully."
										});
										toastEvent.fire();
									}
								}
							});
							$A.enqueueAction(action);
						   
						}
					})

Your help is highy appreciated

Regards,
Fiona

 
Hi Gurus,

In my custom object ERT_Case_Type__c, i have a check box IsProcessed which is by default false

Now I need to make this IsProcessed Flag set to True whenever a batch Job is executed ,here is Pseudo code now what i am looking is 
what exact changes do i need to make in below batch apex code to make this code work with IsProcessed Flag
 
global class copyertbatch6am implements Database.Batchable<sObject> {
  
                    global Database.QueryLocator start(Database.BatchableContext BC) {
                        // collect the batches of records or objects to be passed to execute
                        
                        String query = 'select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM ERT_Case_Type__c where createddate = today and IsProcessed Flag = False';
                        System.debug('ERT Case No is =====>' +query);
                        return Database.getQueryLocator(query);
                    }
                    
                    global void execute(Database.BatchableContext BC, List<ERT_Case_Type__c> exeList) {
                       
                        // process each batch of records
                List<Case_Type__c> listCTD = new List<Case_Type__c>();
                        System.debug('ERT Case No is =====>' +exeList);
                        for(ERT_Case_Type__c exe : exeList)
                        {        
                            listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
                           IsProcessed Flag = True
                        }
                        try {
                            System.debug('ERT Case No is =====>' +listCTD);
                            insert listCTD;
                        
                        } catch(Exception e) {
                            System.debug(e);
                        }
                        
                    }   
                    
                    global void finish(Database.BatchableContext BC) {
                        // execute any post-processing operations
                  }
                }


Your help is higly appreciated

Thanks and Regards,
Hi gurus,

Is there a way i can customize below soql to  include all records after 6am from Today?
 
select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM Case_Type__c  where createddate = today group by Case__c,Level_1__c, Level_2__c,Level_3__c


I need SOQL only ,Apex class wont work,please let me know 

Regards,
Fiona
Dear gurus,

I would like to know if there is possibility of writing a SOQL similar like we do in SQL
like Distinct of Level_1__c,Level_2__c and Level_3__c

Currently SOQL is 
    
select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM ERT_Case_Type__c



How to rewrite to include Distinct of Level_1__c,Level_2__c and Level_3__c

Thanks & Regards,
Fiona
Dear Gurus,

How to make 64%  to 100% code coverage for Test class for Batchable to insert records, iterate over the results, and persist information about any failures to the database

Here is class
global class ertnoonbatch3pm implements Database.Batchable<sObject> {
         global Database.QueryLocator start(Database.BatchableContext BC) {
        // collect the batches of records or objects to be passed to execute
        
        String query = 'select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM ERT_Case_Type__c';
        System.debug('ERT Case No is =====>' +query);
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<ERT_Case_Type__c> exeList) {
        
        // process each batch of records
        List<Case_Type__c> listCTD = new List<Case_Type__c>();
        System.debug('ERT Case No is =====>' +exeList);
        for(ERT_Case_Type__c exe : exeList)
        {        
            listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
            // System.debug('ERT Case No is =====>' +Case__c);
        }

        System.debug('ERT Case No is =====>' +listCTD);
        insert listCTD;
        
        
        Database.SaveResult[] srList = Database.insert(listCTD, false);
        
        // Iterate through each returned result
        for (Database.SaveResult sr : srList) {
            if (sr.isSuccess()) {
                // Operation was successful, so get the ID of the record that was processed
                System.debug('Successfully inserted Case_Type__c: ' + sr.getId());
            }
            else {
                // Operation failed, so get all errors                
                for(Database.Error err : sr.getErrors()) {
                    System.debug('The following error has occurred.');                    
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                    System.debug('Case_Type__c fields that affected this error: ' + err.getFields());
                }
            }
        }            
        
    }   
    
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
    }      

            }

here is test class
@isTest
public class testertnoonbatch3pm{
    static testMethod void testMethod1() 
    {
        List<ERT_Case_Type__c> lstExecutive_RT= new List<ERT_Case_Type__c>();
            Case c = new Case();
        c.Contact_First_Name__c = 'first name';
        c.Contact_Last_Name__c = 'last name';
        c.Address_Line_1__c = 'first name';
        c.Address_Line_2__c = 'first name';
        c.Address_City__c = 'first name';
        c.Address_State__c = 'WA';
        c.Address_Zip__c = '12345';
        c.Home_Phone__c = '123-456-7890';
        c.E_Mail__c = 'abc@abc.com';
        c.hasdevice__c = true;
        c.IMEI__c = 1234567890123.0;
        c.InterestedinTFB__c = true;
        insert c;
        for(Integer i=0 ;i <200;i++)
        {
            ERT_Case_Type__c rt = new ERT_Case_Type__c();
            //5001Q000016wP1BQAU
            rt.Case__c = c.Id;
            rt.Level_1__c ='Customer Service';
            //rt.Level_1__c ='Customer Service'+i;
            rt.Level_2__c ='Customer Care  -  T-Mobile';
            rt.Level_3__c ='Upholding policy - account services';
            system.debug('inserted value'+rt);
           lstExecutive_RT.add(rt); 
            
        
        }
        
        insert lstExecutive_RT;
        
        Test.startTest();

            ertnoonbatch3pm objbatch3pm = new ertnoonbatch3pm();
            
            DataBase.executeBatch(objbatch3pm); 
            
        Test.stopTest();
    }

}

How to make this code100 % code covered ,here are code lines not coveredUser-added image
Hi Gurus,

Need a Test class for Batchable class with database.insert function then saves the results and iterate through each results 
 
global void execute(Database.BatchableContext BC, List<ERT_Case_Type__c> exeList) {
						
						// process each batch of records
						List<Case_Type__c> listCTD = new List<Case_Type__c>();
						System.debug('ERT Case No is =====>' +exeList);
						for(ERT_Case_Type__c exe : exeList)
						{        
							listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
							// System.debug('ERT Case No is =====>' +Case__c);
						}

						System.debug('ERT Case No is =====>' +listCTD);
						insert listCTD;
						
						
						Database.SaveResult[] srList = Database.insert(listCTD, false);
						
						// Iterate through each returned result
						for (Database.SaveResult sr : srList) {
							if (sr.isSuccess()) {
								// Operation was successful, so get the ID of the record that was processed
								System.debug('Successfully inserted Case_Type__c: ' + sr.getId());
							}
							else {
								// Operation failed, so get all errors                
								for(Database.Error err : sr.getErrors()) {
									System.debug('The following error has occurred.');                    
									System.debug(err.getStatusCode() + ': ' + err.getMessage());
									System.debug('Case_Type__c fields that affected this error: ' + err.getFields());
								}
							}
						}            
						
					}   
					
					global void finish(Database.BatchableContext BC) {
						// execute any post-processing operations
					}
				}

 
Hi,

I need to to change below code and use Database.insert() to insert records, iterate over the results, and persist information about any failures to the database ...reason to do above is I want to report Records in Batchable Salesforce apex code such that it should report where the Level2 or Level3 are NULL..Can some one edit the below Batch apex code to use Database.insert() to insert records, iterate over the results, and persist information about any failures to the database

here is current code
global class ertcopybatch3pm implements Database.Batchable<sObject> {
              
                global Database.QueryLocator start(Database.BatchableContext BC) {
                    // collect the batches of records or objects to be passed to execute
                    
                    String query = 'select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM ERT_Case_Type__c';
                    System.debug('ERT Case No is =====>' +query);
                    return Database.getQueryLocator(query);
                }
                
                global void execute(Database.BatchableContext BC, List<ERT_Case_Type__c> exeList) {
                   
                    // process each batch of records
            List<Case_Type__c> listCTD = new List<Case_Type__c>();
                    System.debug('ERT Case No is =====>' +exeList);
                    for(ERT_Case_Type__c exe : exeList)
                    {        
                         listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
                       // System.debug('ERT Case No is =====>' +Case__c);
                    }
                    try {
                      System.debug('ERT Case No is =====>' +listCTD);
                        insert listCTD;
                    
                    } catch(Exception e) {
                        System.debug(e);
                    }
                    
                }   
                
                global void finish(Database.BatchableContext BC) {
                  // execute any post-processing operations
              }
            }

Your help is highly appreciated

Regards.
Fiona
Dear gurus,

I have custom object1 named Case_Type_Data__c with Level_1__c, Level_2__c,Level_3__c
and i have another custom object2 named  ERT_Case_Type__c with same fields Level_1__c, Level_2__c,Level_3__c

A batch copied data from ERT_Case_Type__c to Case_Type_Data__c

Now i try to write SOQL in workbench to find out which records didnt get copied
 
Select Level_1__c,Level_2__c,Level_3__c From Case_Type_Data__c Where Level_3__c NOT IN (Select Level_3__c From ERT_Case_Type__c)

Workbench throws error
MALFORMED_QUERY: semi join sub selects can only query id fields, cannot use: 'Level_3__c'
Please note Id of ERT_Case_Type__c and Id of Case_Type_Data__c doesnt matches hence cant use Id

Please provide me a Join SOQL to get records which didn't got copied from ERT_Case_Type__c to Case_Type_Data__c
Regards
Fiona
 
Hi,

Here is my current Batchable apex code,currently this batch job  copies the data over from the new custom object ERT_Case_Type__c to the old custom object Case_Type__c 

But problem is this job failing where the Level1, Level2 or Level3 are not there.   

This is due to the old picklist restricting based on what values we had in the old picklist on these 3 fields...so I have removed that restriction on the 3 Level fields in Case Type
 
 How can i make sure that Batchable Salesforce apex code  shouldn't be failing where the Level1, Level2 or Level3 are not there.   
 
global class ertcopybatch3pm implements Database.Batchable<sObject> {
				  
					global Database.QueryLocator start(Database.BatchableContext BC) {
						// collect the batches of records or objects to be passed to execute
						
						String query = 'select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM ERT_Case_Type__c';
						System.debug('ERT Case No is =====>' +query);
						return Database.getQueryLocator(query);
					}
					
					global void execute(Database.BatchableContext BC, List<ERT_Case_Type__c> exeList) {
					   
						// process each batch of records
				List<Case_Type__c> listCTD = new List<Case_Type__c>();
						System.debug('ERT Case No is =====>' +exeList);
						for(ERT_Case_Type__c exe : exeList)
						{        
							 listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
						   // System.debug('ERT Case No is =====>' +Case__c);
						}
						try {
						  System.debug('ERT Case No is =====>' +listCTD);
							insert listCTD;
						
						} catch(Exception e) {
							System.debug(e);
						}
						
					}   
					
					global void finish(Database.BatchableContext BC) {
					  // execute any post-processing operations
				  }
				}

Thanks in advance,
Fiona​​​​​​​
How To Make Level_2 and Level_3 as ReadOnly in Salesforce Custome Lightning component

I have a controller which has 3 text boxes ,now i want level2 and level3 as ReadOnly ,how can i do that

Here is custom component currently which has editable Level2 and Level3,my need is to make these 2 fields as read only
User-added imagehere is the .cmp file
 
<aura:component implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="Stack">
						<aura:attribute access="private" type="List" name="selection" default="[]"/>
						<aura:attribute access="private" type="List" name="errors" default="[]"/>

						<lightning:card title="ERT Case Type">
							
							<lightning:recordEditForm aura:id="myForm" objectApiName="ERT_Case_Type__c" onsubmit="{!c.onSubmit}" onsuccess="{!c.onSuccess}">
							<lightning:messages />
							<c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search ERT Case Types Data"/>
							<lightning:inputField aura:id="Level_1__c" fieldName="Level_1__c" />
							<lightning:inputField aura:id="Level_2__c" fieldName="Level_2__c" />
							<lightning:inputField aura:id="Level_3__c" fieldName="Level_3__c" />
							<lightning:button class="slds-m-top_small" variant="brand" type="submit" name="save" label="Save" />
						</lightning:recordEditForm>
						</lightning:card>
					</aura:component>
here is .js file
 
({
						lookupSearch : function(component, event, helper) {
							// Get the lookup component that fired the search event
							const lookupComponent = event.getSource();
							const serverSearchAction = component.get('c.search');
							lookupComponent.search(serverSearchAction);
						},

						useSelected: function(component, event, helper) {
							const selection = component.get('v.selection');
							const errors = component.get('v.errors');
							
							if (selection.length) {
								if(errors.length){  // Clear errors, if any
									component.set('v.errors', []);
								}
								let levels = selection[0].subtitle.split('; ');
								component.find('Level_1__c').set('v.value', levels[0]);
								component.find('Level_2__c').set('v.value', levels[1]);
								component.find('Level_3__c').set('v.value', levels[2]);
							}else {
								// Somebody "selected" empty option = cleared the search box
								component.find('Level_1__c').set('v.value', '');
								component.find('Level_2__c').set('v.value', '');
								component.find('Level_3__c').set('v.value', '');
							}
						},
						onSubmit: function(component, event, helper) {
							debugger;
							event.preventDefault();       // stop the form from submitting
							var fields = event.getParam('fields');
							fields.Case__c = component.get('v.recordId'); // link to "this" Case
							component.find('myForm').submit(fields);
						},
						onSuccess: function(component, event, helper){
							var toastEvent = $A.get("e.force:showToast");
							toastEvent.setParams({
								"title": "Success!",
								"message": "Case Type saved OK, refreshing",
								"type": "success"
							});
							toastEvent.fire();
							$A.get('e.force:refreshView').fire(); // reload page
						}
					})

Your response is highly appreciated

Regards,
Fiona
 
Dear gurus,

Question is as we develop apex code and then we write test class which covers at least 75% code coverage of the apex class,now when I log in to developer console,I am able to see the code coverage which is little off because manually one needs to go to developer console,I want some report which can be shown to senior managers about Salesforce Test code coverage for entire org

User-added image

but is it possible to get this in a sophisticated report very much similar to sonarqube code coverage report
Thanks in advance 
Fiona
Dear gurus.

How to write tests that creates sample Case Type Data records, then runs the search and checks if what was returned matches expectations

here is the apex class
 
public class Stack {
				@AuraEnabled(cacheable=true)
				public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){
					if(String.isBlank(searchTerm) || searchTerm.length() < 2){
						return null;
					}
					String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what
					
					List<Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c
						FROM Case_Type_Data__c
						WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t
						ORDER BY Level_1__c, Level_2__c, Level_3__c
						LIMIT 20];
					
					/* You could also experiment with SOSL?
					records =  [FIND :('*' + searchTerm + '*') IN ALL FIELDS 
						RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0];
					*/
					
					List<LookupSearchResult> results = new List<LookupSearchResult>();
					for(Case_Type_Data__c ctd : records){
						results.add(new LookupSearchResult(ctd.Id, 'Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name,
							String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ')
						));
					}
					return results;
				} 

			}

Regards,
Fiona​​​​​​​
Hey gurus,

stuck in here to write a test class,please suggest a test class ,below test class didn't solved the purpose
 
@isTest
public class testStack {
    public static  testMethod void testCallClass(){
        Account acc = new Account(Name='Test Account');
        insert acc;
        Test.startTest();
        LookupSearchResult lcr = new LookupSearchResult(acc.id,'Account','Test Icon','Test Title','Test Sub-Title');
        system.assert(lcr.getId() == acc.id);
        system.assert(lcr.getSObjectType() == 'Account');
        system.assert(lcr.getIcon() == 'Test Icon');
        system.assert(lcr.getTitle() == 'Test Title'); 
        system.assert(lcr.getSubtitle() == 'Test Sub-Title'); 
        Test.stopTest();
    }
}



here is the aura enabled class for which test class is needed

 
public class Stack {
    @AuraEnabled(cacheable=true)
    public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){
        if(String.isBlank(searchTerm) || searchTerm.length() < 2){
            return null;
        }
        String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what
        
        List<Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c
            FROM Case_Type_Data__c
            WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t
            ORDER BY Level_1__c, Level_2__c, Level_3__c
            LIMIT 20];
        
        /* You could also experiment with SOSL?
        records =  [FIND :('*' + searchTerm + '*') IN ALL FIELDS 
            RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0];
        */
        
        List<LookupSearchResult> results = new List<LookupSearchResult>();
        for(Case_Type_Data__c ctd : records){
            results.add(new LookupSearchResult(ctd.Id, 'Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name,
                String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ')
            ));
        }
        return results;
    } 

}

Regards,
Fiona
Hi Gurus,

Please provide me a test class for below look up class
 
/**
* Class used to serialize a single Lookup search result item
* The Lookup controller returns a List<LookupSearchResult> when sending search result back to Lightning
*/
public class LookupSearchResult {

    private Id id;
    private String sObjectType;
    private String icon;
    private String title;
    private String subtitle;

    public LookupSearchResult(Id id, String sObjectType, String icon, String title, String subtitle) {
        this.id = id;
        this.sObjectType = sObjectType;
        this.icon = icon;
        this.title = title;
        this.subtitle = subtitle;
    }

    @AuraEnabled
    public Id getId() {
        return id;
    }

    @AuraEnabled
    public String getSObjectType() {
        return sObjectType;
    }

    @AuraEnabled
    public String getIcon() {
        return icon;
    }

    @AuraEnabled
    public String getTitle() {
        return title;
    }

    @AuraEnabled
    public String getSubtitle() {
        return subtitle;
    }
}

Regards,
Fiona​​​​​​​
Hi Gurus,
Custom Lightning App named "Stack" giving "You dont have access to this record Contact "
Trying to follow steps in https://stackoverflow.com/questions/64129038/how-to-implement-full-search-in-case-type-using-salesforce/64172475#64172475 
User-added image
Here is Org wide defaults of the custom object ERT Case Type data 

User-added imageHere is apex code of stack
public class Stack {
      @AuraEnabled(cacheable=true)
    public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){
        if(String.isBlank(searchTerm) || searchTerm.length() < 2){
            return null;
        }
        String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what
        
        List<ERT_Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c
            FROM ERT_Case_Type_Data__c
            WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t
            ORDER BY Level_1__c, Level_2__c, Level_3__c
            LIMIT 20];
        
        /* You could also experiment with SOSL?
        records =  [FIND :('*' + searchTerm + '*') IN ALL FIELDS 
            RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0];
        */
        
        List<LookupSearchResult> results = new List<LookupSearchResult>();
        for(ERT_Case_Type_Data__c ctd : records){
            results.add(new LookupSearchResult(ctd.Id, 'ERT_Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name,
                String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ')
            ));
        }
        return results;
    } 

}

Here is Aura component(html part)
<aura:component implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="Stack">
    <aura:attribute access="global" type="List" name="selection" default="[]"/>
    <aura:attribute access="global" type="List" name="errors" default="[]"/>

    <lightning:card title="New Case Type">
        
        <lightning:recordEditForm aura:id="myForm" objectApiName="ERT_Case_Type__c" onsubmit="{!c.onSubmit}" onsuccess="{!c.onSuccess}">
        <lightning:messages />
        <c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search Case Types Data"/>
        <lightning:inputField aura:id="Level_1__c" fieldName="Level_1__c" />
        <lightning:inputField aura:id="Level_2__c" fieldName="Level_2__c" />
        <lightning:inputField aura:id="Level_3__c" fieldName="Level_3__c" />
        <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="save" label="Save" />
    </lightning:recordEditForm>
    </lightning:card>
</aura:component>

Here is Aura component - JS controller part
({
    lookupSearch : function(component, event, helper) {
        // Get the lookup component that fired the search event
        const lookupComponent = event.getSource();
        const serverSearchAction = component.get('c.search');
        lookupComponent.search(serverSearchAction);
    },

    useSelected: function(component, event, helper) {
        const selection = component.get('v.selection');
        const errors = component.get('v.errors');
        
        if (selection.length) {
            if(errors.length){  // Clear errors, if any
                component.set('v.errors', []);
            }
            let levels = selection[0].subtitle.split('; ');
            component.find('Level_1__c').set('v.value', levels[0]);
            component.find('Level_2__c').set('v.value', levels[1]);
            component.find('Level_3__c').set('v.value', levels[2]);
        }
    },
    onSubmit: function(component, event, helper) {
        debugger;
        event.preventDefault();       // stop the form from submitting
        var fields = event.getParam('fields');
        fields.Case__c = component.get('v.recordId'); // link to "this" Case
        component.find('myForm').submit(fields);
    },
    onSuccess: function(component, event, helper){
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Success!",
            "message": "Case Type saved OK, refreshing",
            "type": "success"
        });
        toastEvent.fire();
        $A.get('e.force:refreshView').fire(); // reload page
    }
})

Please help me in removing this access error

Regards,
Fiona
Hi Gurus,
I need to build out a solution to create a search field on the new Case Type Data object in all 3 of the Level fields and populate based on selection.

Similar to SF Global Search I  would like to type 2-3 characters in the text search field and it would find the matching text in the Level1-3 fields and when selected the Level 1-3 field would populate.

What do I need to do to achieve thisUser-added image
Regards,
Fiona
Hi ,

Please help in writing a test class for below Schedulable class
 
global class CopyERTBatchDaily implements Schedulable {
  global void execute(SchedulableContext sc) {
//  batchable b = new batchable(); 
      // your batch class
  CopyERTBatch bbb= new copyertbatch();
  database.executebatch(bbb);
  }
}

Regards
Fiona
Hi Gurus,

Plz help in Writing a Test class for below scheduled apex class Mon Tue wed thu 7am
 
global class CopyERTBatchDaily Implements Schedulable
    {
        global void execute(SchedulableContext sc)
        {
            setERTBatch();
        }

        public void setERTBatch()
        {
            //List<Executive_RT> exeList = new List<Executive_RT>();
            List<Executive_RT> exeList = [select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM Executive_RT];
             // process each batch of records
            List<Case_Type__c> listCTD = new List<Case_Type__c>();
        
        for(Executive_RT exe : exeList)
        {        
           	listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
            //System.debug('ERT Case No is =====>' +Case__c);
        }
        try {
        	
            insert listCTD;
        
        } catch(Exception e) {
            System.debug(e);
        }
            
        }
    }

Regards
Fiona​​​​​​​
Dear gurus,

How do i setup this batch job to execute at 6am PST Mon tuesday wed thursday
 
global class CopyExecutive_RTBatch implements Database.Batchable<sObject> {
  
    global Database.QueryLocator start(Database.BatchableContext BC) {
        // collect the batches of records or objects to be passed to execute
        
        String query = 'select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM Executive_RT_Case_Type__c';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Executive_RT_Case_Type__c> exeList) {
       
        // process each batch of records
List<Case_Type__c> listCTD = new List<Case_Type__c>();
        
        for(Executive_RT_Case_Type__c exe : exeList)
        {        
           	listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
            //System.debug('Executive_RT Case No is =====>' +Case__c);
        }
        try {
        	
            insExecutive_RT listCTD;
        
        } catch(Exception e) {
            System.debug(e);
        }
        
    }   
    
    global void finish(Database.BatchableContext BC) {
    	// execute any post-processing operations
  }
}

Thanks,
Fiona
Hi Gurus,

Step1--> I have a scenario where, in my dependent picklist, first i am setting values for  picklist Level2 and then selected dependent picklist value in Level3
User-added image

Step2--> Now this time removed selection at Level2 ,automatically Level3 selection also got erased and 

User-added image

Step3--> Click Save

User-added image

Here is problem,that value selected in Step2 getting saved rather than the reset value in step3

I have added code to reset values at 
ui:inputSelectOption
but it seems the reset  values from lightning components are not getting reset and saved rather cached values are getting saved after I click save,

Please help in fixing the code, here is the component code
<aura:component controller="PickListHandler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
					<!-- Actions-->
					<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
					<aura:handler name="change" value="{!v.pageReference}"
								  action="{!c.onPageReferenceChanged}" />
					<!-- variable-->
					<aura:attribute name="lstLevel1" type="String[]" />
					 <aura:attribute name="lstLevel2" type="String[]" />
					  <aura:attribute name="lstL3" type="String[]" />
					<span> Level 1</span>
					<ui:inputSelect aura:id="ddLevel1" change="{!c.getLvl1}">
						<ui:inputSelectOption label="-Select-" value="true"/>        
						<aura:iteration items="{!v.lstLevel1}" var="value">          
							<ui:inputSelectOption label="{!value}" text="{!value}" />
						</aura:iteration>
					</ui:inputSelect>
					<span>Level 2</span>
					<ui:inputSelect aura:id="ddLevel2"  change="{!c.getSelectedValue}">
						 <ui:inputSelectOption label="-Select-" value="{!v.clrlv1}"/>        
						<aura:iteration items="{!v.lstLevel2}" var="value">          
							<ui:inputSelectOption label="{!value}" text="{!value}" />
						</aura:iteration>
					</ui:inputSelect>
					 <span>Level 3</span>
					<ui:inputSelect aura:id="ddLevel3" >
						<ui:inputSelectOption label="-Select-" value="{!v.clrlv2}"/>        
						<aura:iteration items="{!v.lstL3}" var="value">          
							<ui:inputSelectOption label="{!value}" text="{!value}" />
						</aura:iteration>
					</ui:inputSelect>
				   <lightning:button variant="brand" label="Save" onclick="{!c.onConfirm}" />
				</aura:component>

here is controller  code
({
					   reset1 : function(component, event, helper) {
							component.set("v.clrlvl", "");
						},
						reset2 : function(component, event, helper) {
							component.set("v.clrlv2", "");
						},onPageReferenceChanged: function(cmp, event, helper) {
							$A.get('e.force:refreshView').fire();
						},
						doInit : function(component, event, helper) {
							var action = component.get("c.getLevel1");
							action.setCallback(this, function(e) {
								if(e.getState()=='SUCCESS'){
									var result=e.getReturnValue();
									component.set("v.lstLevel1",result);
								}
							});
							$A.enqueueAction(action);
						},    
						getLvl1:function(component, event, helper){
						   
							var picklist=component.find('ddLevel1');
							var picklistvalue=picklist.get('v.value');
							var action = component.get("c.getLevel2");
							action.setParams({  'strName' : picklistvalue  });
							action.setCallback(this, function(e) {
								if(e.getState()=='SUCCESS'){
									var result=e.getReturnValue();
									component.set("v.lstLevel2",result);
								}
							});
							$A.enqueueAction(action);
								},
						getSelectedValue:function(component, event, helper){
							var picklist=component.find('ddLevel1');
							var picklistvalue=picklist.get('v.value');
							var picklistdep=component.find('ddLevel2');
							var picklistvaluedep2=picklistdep.get('v.value');
							var action = component.get("c.getLevel3");
							action.setParams({  'strName1' : picklistvalue,
											 'strName2' : picklistvaluedep2});//
							action.setCallback(this, function(e) {
								if(e.getState()=='SUCCESS'){
									var result=e.getReturnValue();
									component.set("v.lstL3",result);
								}
							});
							$A.enqueueAction(action);
						},
						onConfirm:function(component, event, helper){
							var picklist=component.find('ddLevel1');
							var picklistvalue=picklist.get('v.value');
							var picklistdep=component.find('ddLevel2');
							var picklistvaluedep2=picklistdep.get('v.value');
						   
							var picklistdep3=component.find('ddLevel3');
							var picklistvaluedep3=picklistdep3.get('v.value');
							var action = component.get("c.savecasetype");
							
							action.setParams({  'level1' : picklistvalue,
											  'level2' : picklistvaluedep2,
											  'level3' : picklistvaluedep3,
											  'id' : component.get("v.recordId")});
											  
							
							var toastEvent = $A.get("e.force:showToast");
							action.setCallback(this, function(e) {
								if(e.getState()=='SUCCESS'){
									var result=e.getReturnValue();
									if(result==='successfull'){
										toastEvent.setParams({
											"title": "Success!",
											"message": "The record has been inserted  successfully."
										});
										toastEvent.fire();
									}else{
										toastEvent.setParams({
											"title": "Error",
											"message": "The record has not been inserted  successfully."
										});
										toastEvent.fire();
									}
								}
							});
							$A.enqueueAction(action);
						   
						}
					})

Your help is highy appreciated

Regards,
Fiona

 
Dear gurus,

I would like to know if there is possibility of writing a SOQL similar like we do in SQL
like Distinct of Level_1__c,Level_2__c and Level_3__c

Currently SOQL is 
    
select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM ERT_Case_Type__c



How to rewrite to include Distinct of Level_1__c,Level_2__c and Level_3__c

Thanks & Regards,
Fiona
Hi Gurus,

Need a Test class for Batchable class with database.insert function then saves the results and iterate through each results 
 
global void execute(Database.BatchableContext BC, List<ERT_Case_Type__c> exeList) {
						
						// process each batch of records
						List<Case_Type__c> listCTD = new List<Case_Type__c>();
						System.debug('ERT Case No is =====>' +exeList);
						for(ERT_Case_Type__c exe : exeList)
						{        
							listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
							// System.debug('ERT Case No is =====>' +Case__c);
						}

						System.debug('ERT Case No is =====>' +listCTD);
						insert listCTD;
						
						
						Database.SaveResult[] srList = Database.insert(listCTD, false);
						
						// Iterate through each returned result
						for (Database.SaveResult sr : srList) {
							if (sr.isSuccess()) {
								// Operation was successful, so get the ID of the record that was processed
								System.debug('Successfully inserted Case_Type__c: ' + sr.getId());
							}
							else {
								// Operation failed, so get all errors                
								for(Database.Error err : sr.getErrors()) {
									System.debug('The following error has occurred.');                    
									System.debug(err.getStatusCode() + ': ' + err.getMessage());
									System.debug('Case_Type__c fields that affected this error: ' + err.getFields());
								}
							}
						}            
						
					}   
					
					global void finish(Database.BatchableContext BC) {
						// execute any post-processing operations
					}
				}

 
Dear gurus,

I have custom object1 named Case_Type_Data__c with Level_1__c, Level_2__c,Level_3__c
and i have another custom object2 named  ERT_Case_Type__c with same fields Level_1__c, Level_2__c,Level_3__c

A batch copied data from ERT_Case_Type__c to Case_Type_Data__c

Now i try to write SOQL in workbench to find out which records didnt get copied
 
Select Level_1__c,Level_2__c,Level_3__c From Case_Type_Data__c Where Level_3__c NOT IN (Select Level_3__c From ERT_Case_Type__c)

Workbench throws error
MALFORMED_QUERY: semi join sub selects can only query id fields, cannot use: 'Level_3__c'
Please note Id of ERT_Case_Type__c and Id of Case_Type_Data__c doesnt matches hence cant use Id

Please provide me a Join SOQL to get records which didn't got copied from ERT_Case_Type__c to Case_Type_Data__c
Regards
Fiona
 
Hi Gurus,
I need to build out a solution to create a search field on the new Case Type Data object in all 3 of the Level fields and populate based on selection.

Similar to SF Global Search I  would like to type 2-3 characters in the text search field and it would find the matching text in the Level1-3 fields and when selected the Level 1-3 field would populate.

What do I need to do to achieve thisUser-added image
Regards,
Fiona
Hi ,

Please help in writing a test class for below Schedulable class
 
global class CopyERTBatchDaily implements Schedulable {
  global void execute(SchedulableContext sc) {
//  batchable b = new batchable(); 
      // your batch class
  CopyERTBatch bbb= new copyertbatch();
  database.executebatch(bbb);
  }
}

Regards
Fiona
Dear gurus,

How do i setup this batch job to execute at 6am PST Mon tuesday wed thursday
 
global class CopyExecutive_RTBatch implements Database.Batchable<sObject> {
  
    global Database.QueryLocator start(Database.BatchableContext BC) {
        // collect the batches of records or objects to be passed to execute
        
        String query = 'select Case__c, Level_1__c, Level_2__c,Level_3__c  FROM Executive_RT_Case_Type__c';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Executive_RT_Case_Type__c> exeList) {
       
        // process each batch of records
List<Case_Type__c> listCTD = new List<Case_Type__c>();
        
        for(Executive_RT_Case_Type__c exe : exeList)
        {        
           	listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
            //System.debug('Executive_RT Case No is =====>' +Case__c);
        }
        try {
        	
            insExecutive_RT listCTD;
        
        } catch(Exception e) {
            System.debug(e);
        }
        
    }   
    
    global void finish(Database.BatchableContext BC) {
    	// execute any post-processing operations
  }
}

Thanks,
Fiona

 
Hi Gurus,

Please help me in writng a test class for scheduled batch apex below ,i want 100% code coverage please
 
global class ERTExtract255BatchClass implements Database.Batchable<sObject>, Database.Stateful {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT ID,Description,Case_Desc_255__c FROM Case' 
        );
    }
    global void execute(Database.BatchableContext bc, List<Case> scope){
        // process each batch of record
        List<Case> lstCase = new List<Case>();       
        for (Case cas : scope) {
            cas.Case_Desc_255__c = cas.Description.Left(255);
            lstCase.add(cas);  
        }   
        update lstCase;
    }   
    global void finish(Database.BatchableContext bc){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       
    
      AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors,
      a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById,
      a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];
       
      // below code will send an email to User about the status
      String[] email = new String[]{'.com'};
      mail.setToAddresses(email);
      mail.setReplyTo('abc@gmail.com'); 
      mail.setSenderDisplayName('ERT Extract First 255 Char Batch Processing');
      mail.setSubject('Batch Processing '+a.Status);
      mail.setPlainTextBody('The Batch Apex job processed '+ a.TotalJobItems+'batches with '+a.NumberOfErrors+'failures '+'Job Item processed are '+a.JobItemsProcessed);
      Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
    }   
     
}

Thanks,
Fiona​​​​​​​



 
i have created a Junction object as below
User-added image

But when I type below query I don't see data why?
select Id from Case_ERT_Junc__c
User-added image
Dear Friends,
Need a help in writing Batch Job that takes the first 255 characters from the existing long description field and  populates it into the new description field

Basically a batch job to copy first 255 characters from Case_Desc and update it to Case_Desc_255__c

Your help is highly appreciated

Regards,
Fiona