+ Start a Discussion
Calvin NgCalvin Ng 

how can I edit an Apex Class on my production site?

I have a current Apex class in my production, I would like to do a simple tweek to one of the labels used in the Public Group.

I have done the simple change on Sandbox, and its working on Sandbox.

Somehow, I would like to do the same for my Production, but i cannot. I'm not familiar with Apex coding, but i remember it needs some deployment steps from Sandbox into Production.

I need all the guidance as I can get on this.... Any step by step guide would be really great!

Amit GhadageAmit Ghadage
1) In production insetup --> deployment setting  add your sanbox for inbound change set
2) create outbond change set in sandbox 
3) add ApecClass Components you want to change set
4) upload to production and you will get an email after upload
5)Goto prouction setup--> inbound change set
6) click on your change set name and click on deploy
7)After validating classes will be deployed

for more information refer 
S TamanS Taman
Nope!You wont be able to make that change directly in production. There are couple of ways you can do it.
  • Change Set
  • eclipse IDE
First pre-requiste fo any code deployment is Test Class, Its nothing but executing your code my another code e.g. you have some apex class,trigger executing on insert of account, then in test class you need to insert account by DML.
if you already have then you can proceed to next

For Change Set: Follw this Trail head  (https://trailhead.salesforce.com/en/app_deployment/app_deployment_changesets) the best way to learn in detail.

my preferred and quick way is eclipse IDE, 
  1. Download Eclispe with force.com IDE from here   (https://developer.salesforce.com/page/Force.com_IDE)
  2. Create you project repository from Sandbox 
  3. Right click on the class you want to deploy and go to force.com|Deploy to server 
  4. Enter Production credentials (security token if ip is not relaxed on you profile)
  5. And follow steps to deploy.
Step by step guide here (http://www.salesforcetutorial.com/use-force-com-ide/)

let me know if you need any more information.


Calvin NgCalvin Ng
When I tried to validate the Apex. I got the following failures:- Apex Test Failures Class Name Method Name Error Message TestAssignPartNumber TestAssignPartNumber System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Username must be in the form of an email address (for example, john@acme.com): [Username] Stack Trace: Class.TestAssignPartNumber.TestAssignPartNumber: line 15, column 1 TestUpdate_OppLineItems_EveryHalfAnHour Update_OppLineItems_EveryHalfAnHour System.LimitException: Apex CPU time limit exceeded Stack Trace: Trigger.CreatePartNumberHistory: line 19, column 1 TestUpdateOppLineItem UpdateOppLineItem System.DmlException: Update failed. First exception on row 0 with id a002800000ni2LpAAI; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, This field is not editable.: [Name] Stack Trace: Class.TestUpdateOppLineItem.UpdateOppLineItem: line 56, column 1 TestUpdatePartNumber validateTrigger System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_USERNAME, Duplicate Username.
The username already exists in this or another Salesforce organization. Usernames must be unique across all Salesforce organizations. To resolve, use a different username (it doesn't need to match the user's email address). : [Username] Stack Trace: Class.TestUpdatePartNumber.validateTrigger: line 69, column 1 How can I overcome this, the sandbox apex are the same and are running fine in the Production. So I don’t see why they should fail from the validation? By the way, these 4 class names are in the production, should I remove them before I validate them to avoid the failures? Regards, Calvin Ng
S TamanS Taman
@Calvin, No need to delete them from production before deloyement. 

For FIELD_INTEGRITY_EXCEPTION : are you creating user in test classes? if yes, please check that user name should be in email format ,also add some random number in user name by code DUPLICATE_USERNAME issue.
For  FIELD_CUSTOM_VALIDATION_EXCEPTION these name field can be auto number and you are trying to assign some value in test class, if it is auto number you need not populate value in it.

Additionally if these calless are not user full of related to your current apex class then you can go for partial deplyment, Add your test class which is particular to your apex class (which you want to deploy) in this all test claases wont execute but only those which included in you change set, note that individual code coverge has to be either or above 75% . Later you can work on remaining test classes to get fixed.