You need to sign in to do that
Don't have an account?

Test class for database upsert
Hello,
I created one class to upsert using databse,but it is only inserting new records in the object not updating
and the test class code coverage is 88% one line is not covering i.e acc.sic = 'atlanta';
can anybody resolve this issue?
public class upsertAccount{
public static List<Database.upsertResult> upsertAcc(){
List<Account> acclist = [select id,name,Billingcity,sic from Account where Billingcity = '' ];
for(Account acc:accList){
acc.sic = 'atlanta';
//acclist.add(acc);
}
Account newAcc = new Account(name='Acme',Billingcity= 'San Fransicso');
acclist.add(newAcc);
Schema.SObjectField schemaField = Account.Fields.SLASerialNumber__c;
List<Database.upsertResult> Results = Database.upsert(acclist ,schemaField ,false);
return results ;
}
}
Test class
@isTest
public class testUpsertAccount{
public static testmethod void testDatabseupsert(){
List<Database.upsertResult> results = UpsertAccount.upsertAcc();
for(Database.upsertResult result:results ){
system.assert(result.issuccess());
}
}
}
Thanks,
Rushi
I created one class to upsert using databse,but it is only inserting new records in the object not updating
and the test class code coverage is 88% one line is not covering i.e acc.sic = 'atlanta';
can anybody resolve this issue?
public class upsertAccount{
public static List<Database.upsertResult> upsertAcc(){
List<Account> acclist = [select id,name,Billingcity,sic from Account where Billingcity = '' ];
for(Account acc:accList){
acc.sic = 'atlanta';
//acclist.add(acc);
}
Account newAcc = new Account(name='Acme',Billingcity= 'San Fransicso');
acclist.add(newAcc);
Schema.SObjectField schemaField = Account.Fields.SLASerialNumber__c;
List<Database.upsertResult> Results = Database.upsert(acclist ,schemaField ,false);
return results ;
}
}
Test class
@isTest
public class testUpsertAccount{
public static testmethod void testDatabseupsert(){
List<Database.upsertResult> results = UpsertAccount.upsertAcc();
for(Database.upsertResult result:results ){
system.assert(result.issuccess());
}
}
}
Thanks,
Rushi
Something like