Posts

Custom button on Opportunity to clone opportunity with its related List (object)

Create a new Detail Page Button on the Opportunity object. Set Behavior to Execute JavaScript and Content Source to OnClick JavaScript Paste the Below snippet of code in the window {!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")}  {!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")}  var retStr;  retStr = sforce.apex.execute(" CloneOpportunitywithRelatedObject "," cloneOpportunity ",  {oppId:"{!Opportunity.Id}"});  location.replace('/' + retStr);   Create a new Apex class and paste the below snippet of code global class  CloneOpportunitywithRelatedObject  {     webservice static Id  cloneOpportunity (Id oppId) //  pass parameters     {         List < Related_Object__C > relatedList = new List < Related_Object__C > ();   // query all the fields you need...

Trigger to update latest due date of task on Opportunity

Create a new custom field on opportunity called  Update_Due_Date_of_Task__c (Date/Time) and create the below trigger on task object.  Output : If there are multiple tasks on opportunity the above custom field will be updated by due date which is greater from all task's due date. Trigger updateLastActvtyUpdateOnOpty on Task(after update, after insert) {     Datetime lastUpdatedDate;     Set < String > whatIDs = new Set < String > ();     for (Task tskObj: Trigger.new) {         if (tskObj.whatId != null && tskObj.ActivityDate != null) {             whatIDs.add(tskObj.whatId);         } ...

URL hacking to auto populate fields on click of button

Hi Developers !!. This post is regarding the   Custom Button   on  Opportunity  Object which  will help us to create cloned opportunities and auto populate fields with its Line items with the help of URL hacking  Please follow the below steps: 1. Go to setup. 2. Create new detail page button on Opportunity object. 3. Give the Label for button. 4. Set behavior as  'Execute JavaScript'  and Content Source as  'OnClick JavaScript' . Paste the below snippet of code in your window. {!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}  {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}  var  urlhack = "{!URLFOR( $Action.Opportunity.Clone , Opportunity.Id, [cloneli=1,opp11='Unqualified',CFID (Give id of the custom field)=Opportunity.Name])}";  window.open( urlhack ); 5. Go to opportunity layout and add new button in the layout.

Setting a default 'From' address when sending an email from Cases

global class EmailPublisherLoader implements QuickAction.QuickActionDefaultsHandler { // Empty constructor global EmailPublisherLoader() { } public string customLabelValue{get;set;} // The main interface method global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) { QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = null; // Check if the quick action is the standard Case Feed send email action for (Integer j = 0; j < defaults.size(); j++) { if (defaults.get(j) instanceof QuickAction.SendEmailQuickActionDefaults && defaults.get(j).getTargetSObject().getSObjectType() == EmailMessage.sObjectType && defaults.get(j).getActionName().equals('Case.Email') && defaults.get(j).getActionType().equals('Email')) { sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults)defaults.get(j); ...

Custom Button to take Ownership for Case Record

Create a new Detail Button on the Case object. Set Behavior to Execute JavaScript and Content Source to OnClick JavaScript Paste the Below snippet of code in the window  {!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}  var caseObj = new sforce.SObject("Case");  caseObj.Id = '{!Case.Id}';  caseObj.OwnerId = '{!$User.Id}';  var result = sforce.connection.update([caseObj]);  if (result[0].success=='false') {  alert(result[0].errors.message);  }  else {  href= "https://cs16.salesforce.com/ui/support/servicedesk/ServiceDeskPage#/{!Case.Id}" ;  // return to console document.location.reload(true)               // Refresh the Tab } Note : Change the return URL    to Current URL. Enjoy Coding !!

Custom Button for Cloning Opportunity without items.

Image
Hi Developers !!. This post is regarding the   Custom Button   on Opportunity Object which  will help us to create clone opportunities without Line items with default values. Please follow the below steps: 1. Go to setup. 2. Create new custom button for Opportunity object. 3. Give the Label for button. 4. Set behavior as 'Execute JavaScript' and Content Source as 'OnClick JavaScript' . Paste the below snippet of code in your window. try { { !REQUIRESCRIPT("/soap/ajax/14.0/connection.js") } // Below query will helps you to copy all the fields from your opportunity. var result = sforce.connection.query("Select opp.Type, opp.StageName, opp.Amount, opp.AccountId,opp. CloseDate,opp.ForecastCategoryName From Opportunity opp WHERE opp.Id = '{!Oppor...

Test-Driven Development in Salesforce

Image
 Concept - To Get some functionality working now and  improve or refactor it afterwards Hi Developers !!. This post is regarding   Test Driven Development   approach in Salesforce. Before going into any details or explanation about  "Test Driven Development in Salesforce" we need to know about (Test-Driven Development).  What is Test Driven Development (TDD) ?  Test Driven Development is an evolutionary approach to development which combines test - first development where you write a test code before  you write just enough production code to fulfill that test and  refactor (making code clearer, cleaner and elegant) . We can also say that TDD is a method of software development in which UNIT Testing is repeatedly done on source code. TDD is a method which will help us to get a better code in less time with no defects.  Benefits: There are many benefits of using Test Driven Development approach for software development. Some of...