I am trying to update a account using the below method called from an after update, after insert trigger. However I am getting an error - "Attempt to de-reference a null object" while using Account acc = null; in the below code..AND if I use Account acc = new Account() , I am getting the error - missing_argument id not specified in an update call in salesforce.Kindly assist.
Trigger:
trigger testTrigg on CustObj(after insert,after update)
{
for (CustObj cr1 : Trigger.new)
{
myClass.updateAccount(cr1);
}
}
Class:
public static myClass{
public static void updateAccount(CustObj cr)
{
List<Account> acclist = new List<Account>();
for (Account ac : soql query)
{
acclist.add(ac);
}
Account acc = null;
if (acclist.size() > 0)
{
acc = acclist[0];
acc.Name = cr.Account_Name__c;
acc.Other_title_information__c = cr.JobTitle__c ;
}
Database.SaveResult sr= Database.update(acc);
}
}