0

I'm stuck in an issue related to Custom Lookup that I'm using in my visual force page. The custom lookup shows all the account records of a specific record type and also has an option to create a new account record. My client came up with an issue in which the account "Name" that will be created can have special characters like upper invert comma. I resolved the issue when the new record is created with having any special characters in it BUT not able to do the same with the existing records that show up when we click on the lookup. I did some changes but that is not working properly. Here is the piece of code for existing records to get appended in the parent VF page.

What i was using earlier:

<apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>

This works fine with names having no special characters. To include special characters I did these changes.

<apex:actionFunction name="apendLink" action="{!apendLink}" reRender="frm">
    <apex:param name="arg1" assignTo="{!exaccId}" value=""/>
</apex:actionFunction>


 <apex:outputLink onclick="apendLink('{!a.Id}');" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>

Here I am passing the record id (on which we click) to the controller and calling a method which is below:

public pageReference apendLink(){
if(exaccId!=null){
    list<Account> accLists = new list<Account>([SELECT Id,Name FROM Account WHERE Id=:exaccId]);
    if(!accLists.isEmpty()){
       exAccfullName=accLists[0].Name;
       appendWindow=true;
    }
}
return null;
}

======= Here I am using a String and a Boolean variable to c go back to VF page and do some JS action when the boolean becomes true. The String contains the name of the record on which we clicked. Below is the JS the executes after this.

if({!appendWindow}){                
    var name = "{!exAccfullName}";
    var id = "{!exaccId}";
    if(name.indexOf('\'') >= 0 ){
        name = name.replace(/'/g, '&apos;');
    }

    top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}',acid, name, false);
}

This JS excluded the upper inverted comma just for an instance. But it's not working properly. Sometimes it works , sometimes it doesn't. Any suggestion here?

0

Consider encoding the account name and other params prior to passing to server - see javascript encodeURI function. Once passed to server logic, decode it prior to setting up your record - see apex encodingUtil.urldecode function.

0

Instead of

<apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>

Try This Link

<apex:outputLink  onclick="passPara('{!a.Id}','{!a.Name}');" value="javascript&colon;;">{!a.Name}</apex:outputLink> 

JS:-

function passPara(conId, conName)
{
    var name = conName;
    if(name.indexOf('\'') >= 0 ){
        name = name.replace(/'/g, '&apos;');
    }

    top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}',conId,name, false)
}
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.