Thursday, December 27, 2012

Assign class or function to Dom element on the fly

Hello Guys,
        Want to assign the class to dom element on the fly? then simply use javascript function which listed below.

demo.html

Lets assume we have anchor tag on it's click we have to apply css class.

<a id="anchor" href="" target='_blank' class='active' onclick="javascript:open_url(this.id, 'google.com');"> Open this link in new window or tab </a>

// javascript  function
<script type='javascript'>
  function open_url(id, url){
   // verify dom has 'active' class or not
   if ($('#' + id).hasClass('active')) {
     if(url != ''){
    // it's open url in new window
     window.open(url);
   }
  }
}
</script>

Thursday, December 13, 2012

Preventing Recursive Method Calls in Salesforce

Hello Guys,
        Yesterday i was playing with salesforce custom object. I had task to update the object once particular field get updated /inserted (for same object). 

Eg. I have Student__c is custom object on salesforce.

Structure of Student__c object is like:
Id, Name__c, Score_in_maths__c, Score_in_science__c, Total_score__c

So when trying to update any score value required to update Total_score__c  accordingly.  To fulfill  this i have added trigger on Student__c (after update) but it results as recursive loop.

To overcome above issue just followed the steps mention in http://blog.jeffdouglas.com/2009/10/02/preventing-recursive-future-method-calls-in-salesforce/. And it works for me.

Free feel to leave comment or ask queries. :)