Wednesday, January 23, 2013

Adding New Fields to an Existing Report Type in Salesforce - SFDC

In SFDC, one of very common complains from the new users is "Some of my fields are disappeared in Reports in SFDC". This is simply because you have not added those fields to the particular report type.

Just go to your report type and add the required fields and save. Follow these instructions.

  • Click Your Name|Setup|Create|Report Types
  • If the introductory message is there, click on Continue
  • Click on the Report Type which you need to edit
  • Click on Edit Layout in the Fields Available for Reports section
  • In the right hand side you can see all the fields of the objects in your report type.
  • Just select the Object from the drop down list in the View section.
  • Already added fields will be appeared as disabled
  • Select the Fields that you need to add and drop them into the section that you need(If there is no any section for your object, create a new section by clicking Create New Section button at the bottom).
  • After selecting all the required fields save the report type.

That's it. Cheers!!!

Last Modified Date in Salesforce - SFDC

This may be a somewhat silly thing to say to the outer world. But I thought to write this post, assuming that there is at least one people who is suffering from this problem ;)

 In SFDC for all the Standard objects as well as for the custom objects, there is a standard field called LastModifiedDate which is invisible in the field list. But if we are accessing these objects through API calls, then we can replicate this field as well into SQL Database or similar. There we can see that, the field is in DataTime format.

Even though the field is invisible in the field list, when we run a report on SFDC we can see that that field is available in the left panel. Ok, now I'll turn into the problem that I faced and the workaround.

I wanted to check the last modified time of each record(let say Opportunity object). But when I ran a report what the last modified date was giving is only the last modified date(as the name is saying itself ;) ). But I got to know that this field is in the type of DataTime. So, with following workaround, I could able to get the DataTime format of this field.

  • Add a new field to the particular object. In my case, for the Opportunity object.
  • Click on Your Name|Setup|Customize|Opportunities|Fields
  • Under Opportunity Custom Fields & Relationships, click on New 
  • Select the Formula as the Data Type of the field 
  • Give a name to the field and select DataTime as the Return Type and click Next 
  • In the Insert Field section, select the Last Modified Date 
  • Now this is your formula.In the formula area it should only appear LastModifiedDate 
  • That's it. Click Next and Follow the formal instructions if any. 

Finally go back to your report type and add the newly added field there. If you unfamiliar with adding a new fields to existing report type, have a look at here. It should now show the DateTime format of the LastModifiedDate field.

Wednesday, January 16, 2013

Creating HTML elements dynamically with JavaScript

When we are developing web pages using markup languages like HTML, the web page will be appeared as we have already written with HTML. But what if we need to add some more HTML elements, add/edit some of properties of HTML elements even after rendering to browser? JavaScript comes into the game here. Below I have given a JavaScript function to add a row for an existing HTML table with some of HTML elements inside table cells.

function addRow(tableId){
   var table = document.getElementById(tableId);
   var row = table.insertRow(rowCount);

   var cell1 = row.insertCell(0);
   var element1 = document.createElement("label");
   element1.innerHTML = "Cell One-Label";
   cell1.appendChild(element1); 

   var cell2 = row.insertCell(1);
   var element2 = document.createElement("input");
   element2.type = "text";
   element2.value - "Cell Two-Input Text";

   cell2.appendChile(element2); 
   var cell3 = row.insertCell(2);
   var element3 = document.createElement("textarea");
   element3.value = "Cell Three-Text Area";
   cell3.appendChild(element3);
}

By calling this function(using a button click event, etc.) with the 'id' of the relevant table as an argument, we can add a label, input text and a textarea there.

Also when we need to set some attributes to be set dynamically, it also can be done. Below I'm explaining this by using the element1.

element1.setAttribute('id','myLabel'); 
element1.setAttribute("onChange",someFunction());
element1.setAttribute("onkeypress",someFunction());
element1.setAttribute("style","width:65px; text-align:right");

This way, we can add almost all the attributes for an HTML element dynamically.