I am having issues with Upserting data. Here is my code:
global static void MyMethod(string param1, string objName, string param2) {
CustomObject__c record = new CustomObject__c();
record.Param1__c = param1;
record.Name = objName;
record.Param2__c = param2;
record.User__c = UserInfo.getUserId();
record.UpsertField__c = param1 + '_' + UserInfo.getUserId();
//upsert record UpsertField__c;
List<CustomObject__c> myRecords = new List<CustomObject__c>();
myRecords.add(record);
Schema.SObjectField f = CustomObject__c.UpsertField__c;
Database.UpsertResult[] urList = Database.upsert(myRecords, f);
for (Database.UpsertResult ur : urList) {
if (ur.isCreated) {
//set counter to 1 on custom object, something like:
record.Counter__c = 1;
} else {
//increment counter by 1
record.Counter__c++;
}
}
}
Error:
Error: Compile Error: Variable does not exist: isCreated at line 25 column 20
My understaing is that 'isCreated' is part of UpsertResult class. Please help me what I'm doing wrong here