Skip to main content
added 78 characters in body
Source Link
gs650x
  • 2.7k
  • 14
  • 69
  • 106

As per my understanding, the below code should throw System.SObjectException: SObject row was retrieved via SOQL without querying the requested field, but instead it updated the account phone without any exception can someone please help me to understand the same?

public static void SObjectException1() {

    Account act = [SELECT ID FROM Account WHERE Name='GenePoint' LIMIT 1];
    act.phone = '1234567810';
    update act;
}

is it a best practice to not query the fields which we are going to update?

As per my understanding, the below code should throw System.SObjectException: SObject row was retrieved via SOQL without querying the requested field, but instead it updated the account phone without any exception can someone please help me to understand the same?

public static void SObjectException1() {

    Account act = [SELECT ID FROM Account WHERE Name='GenePoint' LIMIT 1];
    act.phone = '1234567810';
    update act;
}

As per my understanding, the below code should throw System.SObjectException: SObject row was retrieved via SOQL without querying the requested field, but instead it updated the account phone without any exception can someone please help me to understand the same?

public static void SObjectException1() {

    Account act = [SELECT ID FROM Account WHERE Name='GenePoint' LIMIT 1];
    act.phone = '1234567810';
    update act;
}

is it a best practice to not query the fields which we are going to update?

Source Link
gs650x
  • 2.7k
  • 14
  • 69
  • 106

SObjectException

As per my understanding, the below code should throw System.SObjectException: SObject row was retrieved via SOQL without querying the requested field, but instead it updated the account phone without any exception can someone please help me to understand the same?

public static void SObjectException1() {

    Account act = [SELECT ID FROM Account WHERE Name='GenePoint' LIMIT 1];
    act.phone = '1234567810';
    update act;
}