I have two lists.Each list return record with some specific lookup field.
lstCurrentRecord :
(Service__c:{Id=a0G4E000000BDJ6UAO, Name=S-61, Displayed_Code_Label__c=TWZ - TWIZY, Car_Set__c=uma, RecordTypeId=0124E0000004OvhQAE, CurrencyIsoCode=EUR})
lstSelectedRecord :
(Service__c:{ Service__c:{Id=a0G4E000000BrzdUAC, Name=S-134, Displayed_Code_Label__c=92J - LODGY, Car_Set__c=ram, RecordTypeId=0124E0000004OvhQAE, CurrencyIsoCode=EUR})
Here am comparing two lists Displayed_Code_Label__c
value.If in lstSelectedRecord does not contains lstCurrentRecord Displayed_Code_Label__c
then add that record in one list with lstCurrentRecord carset
value.
For example
lstCurrentRecord -->Displayed_Code_Label__c=TWZ - TWIZY, Car_Set__c=uma
lstSelectedRecord --> Displayed_Code_Label__c=92J - LODGY, Car_Set__c=ram,
Now i want to insert Service record as
Displayed_Code_Label__c=92J - LODGY, Car_Set__c=uma
. The carset
name is changed and inserted as a new record. How to implement this ?
Apex:
public void retrieveService() {
system.debug('Selected Values >>>>' + strCarsetOption + strNWservice + strCBservice + strOtherservice + strContreOption);
if (strNWservice == 'true') {
List < Service__c > lstSNWService = [select id, name, Displayed_Code_Label__c, Car_Set__c from Service__c where Service_Type__c = 'Simple product'
and Simple_service_type__c = 'Network'
and Car_Set__c =: strCarsetOption
];
List < Service__c > lstCNWService = [select id, name, Displayed_Code_Label__c, Car_Set__c from Service__c where Service_Type__c = 'Simple product'
and Simple_service_type__c = 'Network'
and Car_Set__c =: strCurrentRecId
];
lstService = getUniqueRecords(lstCNWService, lstSNWService);
upsert lstService;
system.debug('lstNWService >>>>' + lstService);
}
}
public List < service__c > getUniqueRecords(List < service__c > lstCurrentRecord, List < service__c > lstSelectedRecord) {
system.debug('lstCurrentRecord<<<<' + lstCurrentRecord);
system.debug('lstSelectedRecord <<<<' + lstSelectedRecord);
mapUniqueService = new map < String, List < Service__c >> ();
List < Service__c > lstServiceAdd = new List < Service__c > ();
if (lstCurrentRecord.size() > 0) {
for (Service__c objService: lstCurrentRecord) {
mapUniqueService.put(objService.Displayed_Code_Label__c, new List < Service__c > {
objService
});
}
}
system.debug('<<<<mapUniqueService' + mapUniqueService);
if (lstSelectedRecord.size() > 0) {
for (Service__c objService1: lstSelectedRecord) {
system.debug('objService1<<<' + objService1);
if (!mapUniqueService.containsKey(objService1.Displayed_Code_Label__c) && mapUniqueService.size() > 0) {
system.debug('<<<<objService1 check' + objService1 + mapUniqueService);
objService1.Car_Set__c = strCurrentRecId;
lstServiceAdd.add(objService1);
} else if (mapUniqueService.size() == 0) {
objService1.Car_Set__c = strCurrentRecId;
lstServiceAdd.add(objService1);
}
}
}
system.debug('<<<<lstServiceAdd' + lstServiceAdd);
return lstServiceAdd;
}
In lstServiceAdd i get the values.Here how to update the carset field which is lookup to service.
Thanks in advance !!