You need to sign in to do that
Don't have an account?
SFDC Developer1
Apex upsert not working
I have two object temp__c and NFSave___c. I am dumping all the data in temp object through data loader in rich text area field(Section__c).then i am sending the data with apex class from Section field to NFSave object fields as per the column position.I am not able to perform upsert as duplicate records are adding in NFSave object.I have mark SSN__c field from NFSave object as external id.Please help as i am stuck here from so long.
global class NJImport implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'select Section__c from temp__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<temp__c> accList){
String textImportSection;
List< NFSave___c > list = new List< NFSave___c>();
for(NFSave___c Import : accList){
textImportSection = Import.Section__c;
if(textImportSection !=null && textImportSection !=''){
NFSave___c Obj = new NFSave___c();
Obj.PAAD_SSN__c = textImportSection.mid(0,9);
list.add(Obj);
}
}
upsert list;
}
global class NJImport implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'select Section__c from temp__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<temp__c> accList){
String textImportSection;
List< NFSave___c > list = new List< NFSave___c>();
for(NFSave___c Import : accList){
textImportSection = Import.Section__c;
if(textImportSection !=null && textImportSection !=''){
NFSave___c Obj = new NFSave___c();
Obj.PAAD_SSN__c = textImportSection.mid(0,9);
list.add(Obj);
}
}
upsert list;
}
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
you are using the wrong List type in for loop " for(NFSave___c Import: accList)"
instead of 'NFSave___c' you have to use 'temp__c' in for loop.
Here is the updated code: Thanks.