I'm creating my first VF page and I'm unable to upsert a new record to my object. Can someone help to review my codes for errors. Everything is fine except that it is not saving. Thanks
When the button Go is pressed, it displaces the existing first name and last name.
public Void GO()
{
mainKey=1;
addItemCount=1;
wrappers=new List<TestingObjectKeyWrapper>();
// get the first 10 Design Activities
List<Testing_Object__c> Designs=[select ID, External_ID__c, First_Name__c, Last_Name__c From Testing_Object__c Where First_Name__c =:First_Name_v and Last_Name__c =:Last_Name_v Limit 10];
for (Testing_Object__c Des : Designs)
{
wrappers.add(new TestingObjectKeyWrapper(mainKey++, Des));
}
}
My wrapper class:
public With Sharing class TestingObjectKeyWrapper
{
Public Integer Key{get;set;}
Public Testing_Object__c Des{get;set;}
Public TestingObjectKeyWrapper(Integer inKey, Testing_Object__C inDes)
{
Key=inKey;
Des=inDes;
}
}
So, the user can choose to add addition first name and last name (New record). Once pressed save, it should upsert the new record.
// save the users work
public PageReference save()
{
PageReference result=null;
Boolean error=false;
List<Testing_Object__c> toUpsert=new List<Testing_Object__c>();
// make sure that if any data has been entered, the
// last name is present as this is required
for (TestingObjectKeyWrapper wrapper : wrappers)
{
if ((String.valueof(wrapper.Des.First_Name__c) == Null) ||
(String.valueof(wrapper.Des.Last_Name__c) == Null))
{
if (String.valueof(wrapper.Des.First_Name__c) == Null)
{
wrapper.Des.First_Name__c.addError('Required');
error=true;
}
if (String.valueof(wrapper.Des.Last_Name__c) == Null)
{
wrapper.Des.Last_Name__c.addError('Required');
error=true;
}
else
toUpsert.add(wrapper.Des);
}
}
if (!error)
{
delete toDelete;
upsert toUpsert;
// return the user to the Design Activities tab
//result=new PageReference('/a0M/o');
}
}