• Raúl Germán Muñoz Torres 9
  • NEWBIE
  • 5 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi All,

I am facing this issue.

Anyone have any idea how to solve this.

public void SaveChanges()
{
List<Account> AccountList = [Select Id, Name,(Select Id From Contacts) From Account where Id=:this.AccountId];


if(AccountList.size() > 0)
{
Account UpdateAccount = AccountList[0];
UpdateAccount.Name = this.Name;
UpdateAccount.AccountNumber = this.AccountNumber;
update UpdateAccount;

if(AccountList[0].Contacts.size() > 0)
{
Contact UserContact = AccountList[0].Contacts[0];
UserContact.FirstName = this.FirstName;
UserContact.LastName = this.LastName;
UserContact.Email = this.PersonalEmailId;
update UserContact;
}
else
{
Contact UserContact = new CanGeneral__c(AccountId = AccountList[0].Id,FirstName = this.FirstName,
LastName = this.LastName, Email = this.PersonalEmailId);
insert UserContact;
}
}
}