Code duplication
Extract into Modules
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.setSaveAsActivity(true); message.setWhatId(allCases[i].Id); message.setTargetObjectId(us[i].Id); Set<String> toAddresses = new Set<String>(); // Specify the address used when the recipients reply to the email. message.setReplyTo('caseshandler@1dqi3r2prtrq7i4heo08xqgw1.tkvxcmao.t.apex.sandbox.salesforce.com');//sandbox //message.setReplyTo('caseshandler@3-358xqu71xlffxddajvgx5vz6d.3mvapeaa.3.apex.salesforce.com'); // Specify the name used as the display name. message.setSenderDisplayName('NationwideBandwidth.com Sales'); message.setSubject(us[i].Name+': '+ ((clientAccount.Name=='none'||clientAccount.Name=='NONE')?clientContact.Name:clientAccount.Name)+' Case::'+allCases[i].Id); message.setPlainTextBody( 'Type of Connection: '+(singleOpportunity.Type_of_Connection__c==null?'':singleOpportunity.Type_of_Connection__c)+'\n\n'+ 'Name: '+(clientContact.Name==null?'':clientContact.Name)+'\n'+ //'Last Name: '+clientContact.LastNAme+'\n'+ 'Company Name: '+((clientAccount.Name=='none'||clientAccount.Name=='NONE')?clientContact.Name:clientAccount.Name)+'\n'+ * * * Try{ if(clientContact.Email!=null){ toAddresses.add(clientContact.Email); } if(us[i].Email!=NULL){ toAddresses.add(us[i].Email); } } catch (Exception e){ System.debug('error: '+e); } //Changin Set for a List List<String> aux=new List<String>(); for(String element : toAddresses){ aux.add(element); } //adding the partners email addresses message.setToAddresses(aux);
aLet it ride!
class Car<<ActiveRecord::Base def turn (new_direction) self.direction=new direction end def brake self.speed=o end def accelerate self.speed=speed + 10 endendclass Bus<<ActiveRecord::Base def turn (new_direction) self.direction=new direction end def brake self.speed=o end def accelerate self.speed=speed + 10 endend----------------------------------------------------#lib/drivable.rbmodule Drivable extend ActiveSupport::Concern def turn (new_direction) self.direction=new direction end def brake self.speed=o end def accelerate self.speed=speed + 10 endendclass Car<<ActiveRecord::Base include Drivableendclass Bus<<ActiveRecord::Base include Drivableend
Use Templates!
#lib/drivable.rbModule Drivable extend ActiveSupport::Concern def turn (new_direction) self.direction=new direction end def brake self.speed=o end def accelerate self.speed=[speed + acceleration,top_speed] endendclass Car<<ActiveRecord::Base include Drivable def top_speed 100 endendclass Bus<<ActiveRecord::Base include Drivable def top_speed 80 endend
useful advise
#lib/drivable.rbModule Drivable extend ActiveSupport::Concern def turn (new_direction) self.direction=new direction end def brake self.speed=o end def accelerate self.speed=[speed + acceleration,top_speed] end def top_speed raise TemplateError, "The Drivable module"+ "requires the including class to define a"+ "top_speed method" end def top_speed raise TemplateError, "The Drivable module"+ "requires the including class to define a"+ "acceleration method" endend
Write a plug in
create a plugin
create a gem
Fogbugz/Jira Gem by: