• BryanTSC
  • NEWBIE
  • 50 Points
  • Member since 2009

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 31
    Replies

We are using JS remoting. Found this interesting race condition:

  1. JS Remoting AJAX request made by user.
  2. Before it completes the user moves to another page
  3. When user moves browser to another page the js remoting ajax request is aborted.
  4. The abort invokes the error handler and we have a generic error handler which pops up a dialog showing exception info.
  5. In some cases, the dialog will flash up for a second because the page navigation away hasn't completed.

This looks ugly and we would prefer if the error handler knew there was a page unload happening and not show the error dialog if this was happening.

So, I tried adding a page unload listener and setting a flag in that which can be subsequently checked.

jQuery(window).unload(function() {
    unloadhappening = true;
});

This approach will work in most ajax designs but won't with JS remoting. JS remoting, calls the error handler before the unload event. Not sure why?

I tried the earlier beforeunload event:

jQuery(window).on('beforeunload', function() {
    unloadhappening = true;
    return '';  
}); 

This won't work because this event just shows up another dialog.

So I tried to add a listener to all anchor tags that have a http(s) hyperlink

jQuery('a[href^=http]').click( function() {
    unloadhappening = true; 
})

This won't work for relative URLs.

So I tried to adding a listener to all anchor tags that have a href

jQuery('a[href]').click( function() {
    unloadhappening = true; 
})

This will filter out components that won't work because it won't filter out components that don't trigger a page unload such as:

   <a href="#adviceTab">Advice</a>

So before I go and write a selector to filter out anything with a fragment identifier, there are also some anchors that are coming form JQuery UI that do:

   <a href="javascript&colon;%20void%280%29%3B" class="calToday"    onclick="DatePicker.datePicker.selectDate('today');return false;">Today</a>

I am starting to think this is a more of a hack that will never work as opposed to a solution. Do you have a good idea for this problem?

The only idea I can think of is to check the exception, error, event info returned by JS remoting for an aborted request. I see: Strings:

Unable to connect with Server 

and

Communication Failure

But they might be also used in another error that has nothing to do with a page unload. So wondering has anyone else seen this and if so what is your solution?

Note I have to use JS Remoting. Using forceTK etc is not an option.

Thanks

I am in the process of converting one of my VF pages to a component so that it can be easily reused across objects.

 

In my VF page I implement a standard controller with an extension class.  The constructor of my extension class pulls in the record from the standard controller so I can perform some describe methods on it:

 

public myControllerExtension(ApexPages.StandardController controller) {
        
        Schema.DescribeSObjectResult objDescribe = controller.getRecord().getSObjectType().getDescribe();
        ...
}

What is the best way to replicate this in the component controller?  I'm aware that the component controller does not have access to the standard controller, with the exception of using attributes to pass some information in.  Are attributes the right way to go?  Would I use an extension class in my page to generate the necessary values to assign to my controller attributes?

 

Thanks in advance for your assistance!

Oh this seems so simple, yet I'm stuck!

 

Here's what I have now in my controller:

    public date d {
        get{
            d = date.today();
            return d;
            }
            set;
       }
    
    
    public List<event> all {
    get {
    all = [select subject, activitydate, location from Event where activitydate = :d Order By location ASC];
    return all;
    }
    set;
    }

 

All is peachy and the page loads up Today()'s info just fine.

 

Now, what I really want to do is load up the page initially with today's date and resulting info, but also have a button called "Next" that will add 1 day to the current date and update an outputPanel on my page with the new query results when clicked.

 

I know I need to add a function for the button action, but I'm not sure how to change the code above to manipulate the date variable accordingly.

 

Thanks in advance for any help you might provide!

Hi Folks,


I have a custom child object of Contact called Inquiry_History__c.  I developed a trigger so that whenever an inquiry history record is created that meets certain criteria, a task is created and assigned to the user specified in the inquiry history custom "Owner" field (a lookup to USER, automatically assigned via workflow upon creation).

 

Everything works as anticipated when adding records the good 'ole fashioned way.  However, I have a form hosted on VF sites that creates a Contact and associated inquiry history record that is now flashing the "Authorization Required' page on submit.

 

Where should I begin to look for the cause of this?  I'm not sure how I can debug this process to figure out why the webform is being halted.

 

Trigger:

 

trigger callInquiry on Inquiry_History__c (after insert) {

List<Task> taskList = new List<Task>();

    for (Integer i=0; i<trigger.new.size(); i++) {
    
        if(
        (Trigger.new[i].XStudent_Type__c == 'FF') && 
        ((Trigger.new[i].XCollege__c == 'RSC') || (Trigger.new[i].XCollege__c == 'SCA'))) {
            taskList.add(
                new Task(
                    whatid=Trigger.new[i].Id,
                    whoid=Trigger.new[i].XContact__c,
                    OwnerId=Trigger.new[i].XOwner__c,
                    Subject='Call New Inquiry',
                    ActivityDate = Date.today()+7
            ));
        }
    
    }
    
    insert taskList;

 

Thanks for any insight you can provide!

I currently set up our custom buttons with

 

https://na8.salesforce.com/a0C/e? 

 

When I go into the sandbox I have to modify the intance number. Someone told me you can exclude the instance so you don't have to modify sandbox custom buttons.

 

What is the short cut?

I have a custom controller extension for a CampaignMember VF page that looks like:

 

public class landingSave {

public CampaignMember cm;
    
    public landingSave(ApexPages.StandardController stdController) {
        this.cm = (CampaignMember)stdController.getRecord();
    }

    
    public PageReference submit() {
   
        update cm;

        PageReference pageRef = new PageReference('http://www.someaddress.com');

    return pageRef;
  }

}

 My test class currently looks like:

 

@isTest
private class TestlandingSave{

static testMethod void mylandingSave() {


PageReference pageRef = Page.Discover;
Test.setCurrentPage(pageRef);

Lead l = new Lead(lastname='smith');
Campaign c = new Campaign(Name='test campaign');
CampaignMember cm = new CampaignMember(lead=l, campaign=c, status='sent');

ApexPages.StandardController sc = new ApexPages.StandardController(cm);
landingSave controller = new landingSave(sc);
	<!-- I THINK I'M MISSING SOMETHING HERE -->
cm.XEmail__c = 'acme@gmail.com';


String nextPage = controller.submit().getUrl();

System.assertEquals('http://www.someaddress.com', nextPage);

 }
}

 

Any pointers?!  Thanks :smileyhappy:

 

 

 

 

A couple of questions here:

 

1)  Does this URL Rewriter class look functional?  I thought I read that I didn't necessarily need the second generateURL function, but I'm not sure.

 

 

global with sharing class myRewriter implements Site.UrlRewriter {

String VIP_PAGE = '/VIP/';
String VIP_VISUALFORCE_PAGE = '/VIP?id=';

global PageReference mapRequestUrl(PageReference
myFriendlyUrl){
String url = myFriendlyUrl.getUrl();
if(url.startsWith(VIP_PAGE)){
String name = url.substring(VIP_PAGE.length(),
url.length());

Lead ld = [select id from Lead where XUniqueSearchId__c =:
name LIMIT 1];

return new PageReference(VIP_VISUALFORCE_PAGE + ld.id);
}

return null;
}

global List<PageReference> generateUrlFor(List<PageReference>
mySalesforceUrls){

return null;
}

}

 

 

2) What should the test class for this consist of?

 

Thank you in advance for any assistance you may be able to provide!

I am looking to create a Visualforce page that will serve as a data collection form on our website.  The user will ultimately be creating a contact record (linked to an existing account via a lookup) and then several child records (inquiry history, extra curricular interests, family relationships, etc.)  I would like the user to have the ability to create more than one of any of these child records during this process.

 

Visual:

 

Contact (1)
--Inquiry History (1)
--Extra Curricular Interests (Many)
--Family Relationships (Many)
--Test Scores (Many)

 

1)  Is this feasible?

2) What technique is best suited for this type of action?

 

 Has anyone used  the Lightbox Visualforce component provided by force.com labs to call a visualforce page

 

The link for the App on Appexchage is 

 

http://sites.force.com/appexchange/apex/listingDetail?listingId=a0N30000001g3u0EAA

 

 This is a free app which has a visual force component <c:lightbox>

 

I want to show some visuaforce code in it. 

 

 

thanks