Browse Author: trupti.dhoka

jQuery PostMessage (Cross-Domain Messaging)

From long back sending messages between windows was only possible if the windows used the same protocol, port, and host. The postMessage() method helps to solve this issue by providing a way to securely pass messages across domains.

In this blog post I’m going to explain how to use the postMessage() method to communicate between a controller window and a receiver window running different domains.

The postMessage() method accepts two parameters.

  • message – A string or object that will be sent to the receiving window.
  • targetOrigin – The URL of the window that the message is being sent to. The protocol, port and hostname of the target window must match this parameter for the message to be sent. Specifying “*” will match any URL however this is strongly discouraged for security reasons.

This method should be called on the window that the message is being sent to.

Set Event Listener on the Receiver Window

When postMessage() is executed successfully on sender window a MessageEvent will be fired on the receiving window. The event passed into the listener callback has a property called data that can be used to access the string or object that was sent by postMessage().

window.addEventListener(‘message’, function(m)

{

var message = m.data;

});

Here Data is a property which holds string or abject passed by postmessage().

Set postMessage on the Sender Window

<script type=”text/javascript”>

$(document).ready(function ()

{

$.postMessage(‘Postmessage Example’,’http://example.com/’);

})

</script>

Browser Support For postMessage

IE Firefox Chrome Safari Opera
8+ 3.0+ 1.0+ 4.0+ 9.5+

Summary

Few security considerations that need to be taken into account when using postMessage() are as below.

  • First make sure that you are always specifying full URLs as your targetOrigin parameter and not just using wildcards (*), otherwise you could accidently send data to a malicious website..
  • postMessage() is a really handy tool to have in your toolbox, especially if you do a lot of work with iframes.

How to add Chatter Feed for a record in visualforce pages

Chatter feeds show you recent activities performed by people and on records in your Salesforceorganization. Salesforce Touch lets you view your Chatter feed, group feeds, profile feeds, and record feeds.

You must follow people and records to see their updates in your Chatter feeds. Chatter feeds display on profiles, groups, the Home tab, topic detail pages, and on record detail pages. Typically, you see feed updates for:

  • Chatter feed comments and posts
  • Posts, comments, and files on Chatter groups you’re a member of
  • Shared files and links
  • Tasks and events
  • Converted leads
  • Record field changes, like changes to record owner and closed opportunities and cases

<!— code for Chatter Feed for Login User —>

<apex:page >

<apex:outputPanel layout=”block” style=”overflow:auto; height:540px; width:500px; margin:0 1px”>

<chatter:feed entityId=”{!$User.Id}”/>

</apex:outputPanel>

</apex:page>

Hope this helps you.

Thank You!

 

Avoid recursion of Trigger

Recursive trigger is frequently arising issue in Salesforce triggers. Recursion in trigger means a trigger calling itself again and again. Recursion in trigger occurs when we’ve added some DML statements in trigger and same DML condition is used for trigger firing.

A recursive trigger is one that is called over and over, if not controlled will result in this error…

maximum trigger depth exceeded

for example,

trigger update_record on login__c(before insert){

insert new login__c();

}

In above code , when one login __c object record is created by the user, the trigger executes and then inserts another record of the same type, which causes the trigger to execute again and again.

To avoid such type of situation we need to use static variables .single copy of static variable is shared by all the instances of the same class.

public class Count {

public static boolean insert_once = true;

}

trigger update_record on login__c(before insert){

if(Count .insert_once)

{

Count.Insert_once=false;

insert new login__c();

}

}

In the same transaction,static variable don’t retain its value between different trigger context.

This will call the trigger only once and hence avoid recursion.

Hope this helps you.

Thank you!

 

 

How to Create Tab Panel in Salesforce

This blog will provide you information about creation of tabpanel in salesforce.

TabPanel is a page area that displays as a set of tabs. When a user clicks a tab header, the tab’s associated  content displays, hiding the content of other tabs.

Steps

1. Create a new visualforce page (Setup → Build → Develop → Pages)

2. Write the below code inside page.

In below code I’m showing related lists of standard object Account in different tabs. when user click on any of tab, it will show related list of corresponding object related to account.

<apex:page standardController=”Account” sidebar=”true” tabStyle=”account”>

<apex:tabPanel switchType=”client” selectedTab=”tabdetails” id=”AccountTabPanel”>

<apex:tab label=”Information” name=”Information” id=”Information”>

<apex:detail relatedList=”true” title=”true”/>

</apex:tab>

<apex:tab label=”Contacts” name=”Contacts” id=”Contact”>

<apex:relatedList subject=”{!account}” list=”contacts” />

</apex:tab>

<apex:tab label=”Opportunities” name=”Opportunities” id=”Opp”>

<apex:relatedList subject=”{!account}” list=”opportunities” />

</apex:tab>

<apex:tab label=”Open Activities” name=”OpenActivities” id=”OpenActivity”>

<apex:relatedList subject=”{!account}” list=”OpenActivities” />

</apex:tab>

<apex:tab label=”Notes&Attachments” name=”Notes & Attachments” id=”notesattach”>

<apex:relatedList subject=”{!account}” list=”CombinedAttachments” />

</apex:tab>

</apex:tabPanel>

</apex:page>

 

Above visualforce page should be look like below image in the browser.

Hope this post helps you.

Thank You!

How to add Activity History while sending emails in Salesforce

Hi Friends, many of you know the Salesforce SingleEmailMessage method,In fact you have used it in your apex code. But when we send mail through this method by default it doesn’t add mail into related list of recipient’s activity history.
If you are stuck with this type of issue, then below I’m providing the solution for this.

setSaveAsActivity(true);

Add this method into your code which will add sent mail to the activity History related List.

Follow the example given for better understanding:
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{‘Receipient’s Email’};
String[] ccAddresses = new String[] {‘Additional Receipient’};
mail.setTargetObjectId(receipient.id); // Put setTargetobjectid value as per your requirement.
mail.setCcAddresses(ccAddresses);
mail.setSenderDisplayName(‘SalesforceLogin Test’);
mail.setSubject(‘Subject Test’);
mail.setSaveAsActivity(true); //add mail to the activity history
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setHtmlBody(‘Hi! Salesforce user’);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

Hope this post Helps You!

 

Show/Hide fields as Picklist value changes using Deluge script in Zoho

Sometimes we need to show/hide  certain fields as picklist value changes for example  there is field called ‘Reason’ and we want to hide this field as picklist ‘Product type’ changes to ‘Research’.

We can achieve this by configuring fields action in deluge script.

steps

  • Go to the field on which you want to add action ,in above example ‘Product type’.
  • Field Deluge Name is the name of the field we’ll refer in the deluge script.
  • Select->field properties->Configure field action.
  • Select Field Actions -> Type -> On User input block in Script builder.This action will be executed when user changes field value.

  • Drag if-else condition statement.
  • add logic as below image& save the script

The ‘Reason’ field will be hide as picklist ‘Product type’ changes to ‘Research’, as shown below.

 

How to Create a subform in Zoho

A subform is a form that is inserted into another form. In a one-to-many relationship, each parent record associates itself with multiple children. Using Subforms, users can display the parent and child records in one place without having to switch between forms.

Zoho have field type ‘subform’ which you can insert blank form /existing form in the main form.
To add the subform in the main form

1]Edit the main form ->add new subform(field type is present in the left panel)->Drag-n-drop subform where you want on the main form.
2]On the adding subform it’ll ask you for the new blank form or existing form.
3]Add new fields in the subform and save the changes.

After adding form you can add records in subform  using ‘add new’ button as shown in below image.

The Main Form report will display all the records with the values of the selected subform fields

The ‘Column property’ in the main form report allows you to customize the sub form report also.

Hope this helps you!
Thank You!


Converting Normal to Stateless Form in Zoho

Regular Form

By default, when a Form is created, Zoho Creator will have a table generated at the back-end to store data submitted through the Form. These Forms are called Regular/Normal Forms.

For example, when you create a  Form ‘Order Details’, a table named  ‘Order Details’ is created and  all data submitted through the form will be stored in this table. The ‘Order Details’ will display the data stored in the ‘Order Details’ Form/table.

Stateless Forms do not store data in the backend. An existing form can be converted to a Stateless Form directly from the GUI.

Steps ->

1.From the Dashboard page of the application, click on Create New -> Form.

2.In the New Form dialog box, select the Form type as Form Template.

3.Choose a Form name for the duplicate form. Since the form already contains the existing form name, choose a different name for the form.

4.Select a form to convert to stateless form, from the Choose your Template drop down list.

5.The Choose your template drop down list consist of all the forms listed in the application.

6.Choose a particular form from the My Forms Section of the drop down list.

7.Select a Section under which the form has to be listed.

8.Uncheck the Data will be stored in Zoho Creator checkbox and click on Create button to generate the Stateless form.

 

How To create Stateless form In Zoho Creator

When you create a new form to your application, there is one check-box option “Data will be stored in creator“, De-selecting this option will create the Form as a Stateless Form with custome buttons that does not generate a table at the back-end as Normal form.  you can add custom buttons and write your own logic on  “on click” event of the form.

Creating a Stateless Form

To create a stateless form without data storage,

  • Goto Create new->form option
  • fill the form details such as form name.
  • Deselect optionData to be stored in Zoho Creator.(As shown in the image)
  • on Clicking create Stateless form will be created.

You can drag-n-drop fields in the form as per your requirement.

  • To add button with custom logic click on (+) in the form.

Types of Button

  • Button-Invokes ‘On click’ action specified on mouse click.
  • submit-Invokes ‘On click’ action if enter key is pressed.
  • Reset-We can’t add ‘on click ‘ action on this button as it just takes form to the initial phase.

Once added custom button

  • To perform any action on click of the form button, add the required deluge script in the Form Actions – < Form Button Name> – On Click block of the Workflows tab.
  • Save the script
  • Click on Access this application and enter data to the stateless form. On click of the form button, the script added to the“On Click” block will be executed.

Thank You!


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box