I have two custom objects, the Rate Cards and the Rate Card Lines. What i need to do is to create rate card and rate card line records by deserializing two json files(one for the rate cards and one for the rate card lines). I have done the deserialization into two separate functions which return to my main function the records which i have to create. However, i need to connect my lines to my Rate Card records based on an external id(in Rate Cards). Also, a lookup field exists within the rate card lines object. When i try to populate the rate card line lookup with the external id, the field is not populated. Can you help me of how to accomplish it? My code bellow:
for(Integer i=0; i< pConfList.size(); i++){
String extId;
for(attachment att: [select parentId, body, name from attachment where name like '%Rate Card%' and parentId =: pConfList[i].id]){
//system.debug(att.Body.toString());
if(/*pConfList[i].cscfga__Product_Definition__r.Name == 'Electricity' || */pConfList[i].cscfga__Product_Definition__r.Name == 'Custom Electricity'){
if(att.Name.startsWithIgnoreCase('Rate Card Information')){
//String pSubType = prodSubTypeList[j].cscfga__Value__c;
String pSubType = pConfList[i].el_Product_Sub_Category__c;
Id recordTypeRC = Schema.SObjectType.cspmb__Rate_Card__c.getRecordTypeInfosByName().get('Electricity').getRecordTypeId();
list<cspmb__Rate_Card__c> createRateCard = el_CustomerApprovalTriggerHandler.deserializedRateCard(att.Body.toString(),
pConfList[i], pBasket[0].csordtelcoa__Account__c,
pSubType, recordTypeRC);
for(cspmb__Rate_Card__c RC: createRateCard){
toBeCreatedRCList.add(RC);
}
extId = createRateCard[0].el_External_Id__c;
system.debug(extId);
system.debug(createRateCard);
system.debug(createRateCard[0].el_External_Id__c);
}
if(att.Name.startsWithIgnoreCase('Rate Card Line Information')){
Id recordTypeRCL = Schema.SObjectType.cspmb__Rate_Card_Line__c.getRecordTypeInfosByName().get('Electricity').getRecordTypeId();
list<cspmb__Rate_Card_Line__c> createRateCardLines = el_CustomerApprovalTriggerHandler.deserializedRateCardLines(att.Body.toString(),
pConfList[i], pBasket[0].csordtelcoa__Account__c,
recordTypeRCL);
system.debug(extId);
cspmb__Rate_Card__c RCReference = new cspmb__Rate_Card__c(el_External_Id__c = extId);
system.debug(RCReference);
system.debug(RCReference.id);
for(cspmb__Rate_Card_Line__c RCL:createRateCardLines){
system.debug(RCL);
system.debug(RCL.cspmb__Rate_Card__c);
RCL.cspmb__Rate_Card__c = RCReference.id;
system.debug(RCL.cspmb__Rate_Card__c);
toBeCreatedRCLList.add(RCL);
system.debug(createRateCardLines);
}
}
}
The RCReference.id; is currently null while if i use the RCReference; it has the correct value but i get compile error.