You need to sign in to do that
Don't have an account?

If we are getting an Object from Select Query and want to update 1 field in that object then do we need to select all fields in that object
Suppose Object Obj__c having 3 fields: Field1__c, Field2__c and Field3__c.
Suppose we do Obj__c obj1=[select Field1__c from Obj1__c where id=:someId]; //Suppose all fields are hainvg value.
obj1.Field2='ABCD';
update obj1;
Now, problem here is Field3__c is nullified.
So, do we have to give all fields in SOQL if we want to update that object (even for 1 field)?
Any solution is there if I don't want to select all fields? Or any other way is there?
Suppose we do Obj__c obj1=[select Field1__c from Obj1__c where id=:someId]; //Suppose all fields are hainvg value.
obj1.Field2='ABCD';
update obj1;
Now, problem here is Field3__c is nullified.
So, do we have to give all fields in SOQL if we want to update that object (even for 1 field)?
Any solution is there if I don't want to select all fields? Or any other way is there?
All Answers
//Sample code
Account a = [SELECT Name FROM Account a where a.id = : id]; //id of that record which is you want update
a.name = 'vamshi';
update a;
You need to query for how many fileds you want to update.
I was doing:
toDisplay=obj1;
but I need to query it again if I want all the fields like:
toDisplay = [SELECT id, Field1__c, Field2__c, Field3__c FROM Obj__c where id=:obj1.id];
After that it is showing correct.
Thanks to all for clearing the doubt!