function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave Scott (UK)Dave Scott (UK) 

Add two lines of code to an Apex Class


We have an Apex Class that we need to add two lines of code to.

We've tested the code in Sandbox and used Eclipse IDE software to make the changes and seems very easy to make the changes by right clicking on the code in Eclipse and selecting 'Save to Server'.

I'd like to know when we come to deploy the changes in our production org is it just as easy to do, i.e. open up the production Apex Class in Eclipse, add the two lines that we verified works fine in Sandbox and simply just right click and select 'Save to Server'?

Is that or am I missing something?

Many thanks,
Yes it is as simple, provided the 2 lines you added are covered in the test class. If you have less than 75% after adding the lines, you cannot save the class to Prod.
This is NOT recommended approach though. You need to add the code, modify the test class and test it in Sandbox first. Then deploy these changes using Change Set/Eclipse to production org. Though it might look long process, the best doesn't come easy.

Abhishek Prasad 8Abhishek Prasad 8
Hi Dave,
I am sure you must be knowing that there is something known as Test Class in Salesforce. It is written against every Apex Class/ Trigger etc. It simply judges how many lines of your code are actually relevant and used in the application. Salesforce mandates that the atleast 75% of your codes must be in use. Please google Test Classes in case if you dont know about this. There is enough material available.

One Pro Tip: if you organisation's code coverage is more than 75(or say may be >80%), then addidng these two lines MIGHT NOT affect this test class coverage, and you may not have to write/update your test class. Apart from that, its easy to deply codes in Production. Just you need to attentive on what you are doing.