+ Start a Discussion
Ryan ReeseRyan Reese 

how do i deploy code

So I entered this code in my sandbox with a test opportunity and chatter group but how do I deploy to production

trigger OppWonChatter on Opportunity (after insert, after update) {

String status;
String OppAccName;
String OppOwnerName;
FeedItem post = new FeedItem();
    
    for(Opportunity o : Trigger.new) {
        if(o.OwnerId == '00560000001MxXV') { //It will not post record for for this user to group. changed last letter to cap v so i can test
            return;
        }
        else {
            if(Trigger.isInsert ) {
                if( o.IsWon == true ) { //This will be executed on new record insertion
                    for (Opportunity oppty : [SELECT Account.Name, Owner.Name FROM Opportunity WHERE Id =:o.Id] ) {
                        OppAccName = oppty.Account.Name;
                        OppOwnerName = oppty.Owner.Name;
                    }    
                    status = OppOwnerName + ' just won ' + OppAccName + ' for ' + o.expectedrevenue + '!';

                    
                    post.ParentId = '0F9m00000008ZTM';
                    post.Title = o.Name;   
                    post.Body = status;
                    
                    insert post;
                }
            }    
            else {
                if ( Trigger.isUpdate ) {
                    if( o.IsWon == true ) { //This will be executed on update to existing record
                        for (Opportunity oppty : [SELECT Account.Name, Owner.Name FROM Opportunity WHERE Id =:o.Id] ) {
                            OppAccName = oppty.Account.Name;
                            OppOwnerName = oppty.Owner.Name;
                        }    
                        status = OppOwnerName + ' just won ' + OppAccName + '!';
                                          
                        post.ParentId = '0F9m00000008ZTM';
                        post.Title = o.Name;
                        post.Body = status;
                        
                        insert post;      
                    }
                }
            }
      
James LoghryJames Loghry
Changesets will be the easiest way for you deploy from Sandbox->Production.  First, you will have to log into production to enable the change set connection, however.  You can do this by going to Setup->Deployment->Deployment Settings, and enabling the connection for your sandbox.  Next, you'll have to fix your code to remove your references to hard coded Ids.  If you're deploying this to production, it's likely the Ids will be different.  Furthermore, it's just a worst practice to hard code Ids like that.  Third, you'll have to create a test class for the trigger if you haven't done so already.  Last, you'll have to add the trigger, test class, and any custom fields or other apex classes you need to an outbound change set, then upload it to production.

See the following link on change sets for more info: https://help.salesforce.com/HTViewHelpDoc?id=changesets.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=changesets.htm&language=en_US)
Sai Ram ASai Ram A
Hi Ryan Reese

As James Loghry mentioned, Changeset would be the best approach for Newbie(beginner)
Follow some best practices for Coding
75% of code coverage is required to deploy Apex Class to Prod, Every trigger must have some test coverage 
(https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm)

Hope ths Helps

Thanks
BLearn
Ryan ReeseRyan Reese
If building this code didnt take me long enough, now I have to build a test class. Thank you for your help
How would I build the test class and what would be the basic structure be?
Sai Ram ASai Ram A
Follow the link https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods 


Thanks
 
Ryan ReeseRyan Reese
If i dont hardcode the chatter group id, what do I put in its replacement and know to reference that exact group