You need to sign in to do that
Don't have an account?
Trif Cristian 7
Helpp
Hello, im a newbie and i need some help. I have the next logic in my apex class, i just copied from internet so i dont know exactly whats happening, im not convinced. So, here it is:
Account a =[SELECT name, phone, fax, industry where name = 'Dell'];
if(a.Industry != 'Industry')
a.Industry = 'Industry';
update a;
So basically it saying that fetch name, phone, fax, industry from an existing account with the name Dell. And here on if im confused. If industry field not equal to industry then update that field to industry? Did i say wrong? On if then else statement why we dont have curly brackets? and where is the else statement?
Account a =[SELECT name, phone, fax, industry where name = 'Dell'];
if(a.Industry != 'Industry')
a.Industry = 'Industry';
update a;
So basically it saying that fetch name, phone, fax, industry from an existing account with the name Dell. And here on if im confused. If industry field not equal to industry then update that field to industry? Did i say wrong? On if then else statement why we dont have curly brackets? and where is the else statement?
You only have one code inside your if condition thats why curly brackets are missed and your logic is correct though code has a small error. Corrected code is given below. (Id is queried in all soql queries you dont need to give it separately).
Let me know if you need more clarifications.
Mark it as best answer if it solved your doubts.
Regards
All Answers
To update a record we must need record Id
You missed Id in your query.
Let me know if you have any issues.
Mark it as best answer if it helps.
Thanks.
You only have one code inside your if condition thats why curly brackets are missed and your logic is correct though code has a small error. Corrected code is given below. (Id is queried in all soql queries you dont need to give it separately).
Let me know if you need more clarifications.
Mark it as best answer if it solved your doubts.
Regards