+ Start a Discussion
SanchSanch 

New Contact Button override Not working

Hi Guys,

 

I have an issue with New Button Override. I have a custom visualforce page for the Account. When the user clicks the new button to create a contact a method is called. The method does the following:

 

String newContactUrl = '/003/e?retURL=/' + this.acct.Id +'&accid=' + this.acct.Id;
        
return new PageReference( newContactUrl );

 

Also, The Contact's standard New Button is overriden with an s-control. In the s-control, I check the user's group, if they are a certain group I send them to a custom contact edit page otherwise I redirect them to standard salesforce page. Here is the code:

 

<script> 

function load() { 

if (('{!User.Group__c}' == 'TRG') || ('{!User.IsTRG__c}' == 1)){ 
var acctId = '{! Account.Id}'; 
if ( acctId == null || acctId == '' ) 
parent.location.href = '/apex/TRGContactEdit?RecordTypeId={!Contact.RecordTypeId}&cancelURL={!$Request.retURL}&saveURL={!$Request.retURL}&retURL={!$Request.retURL}'; 

else 
parent.location.href = '/apex/TRGContactEdit?con4_lkid={!Account.Id}&con4={! Account.Name}&RecordTypeId={!Contact.RecordTypeId}&retURL={!$Request.retURL}'; 

} 
// if any other user direct to default Contact detail view 
else { 

parent.location.href= '{!URLFOR($Action.Contact.NewContact, null, [con4_lkid=Account.Id,retURL=$Request.retURL], true)}'; 

} 
} 
</script> 

<body onload=load();> 
</body>

 

 

This works for most of the Accounts, but one of the account that I am trying, it doesn't work. It get a blank page with error on page. The error that I got by double clicking the page is:

 

Message: Expected ';'
Line: 13
Char: 84
Code: 0
URI: https://cs3.salesforce.com/servlet/servlet.Integration?lid=01NQ0000000CiDT&ic=1


Message: Object expected
Line: 25
Char: 1
Code: 0
URI: https://cs3.salesforce.com/servlet/servlet.Integration?lid=01NQ0000000CiDT&ic=1

 

For the user that I am using, it should go to the standard salesforce edit page for contact. It works for most of the accounts. But for one account, it's not working. Please help. Thanks.

 

Sanch

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Does the account in question have a single quote in the name?  If so, in the following code, the inclusion of the account name merge field will terminate the string:

 

 

else 
parent.location.href = '/apex/TRGContactEdit?con4_lkid={!Account.Id}&con4={! Account.Name}&RecordTypeId={!Contact.RecordTypeId}&retURL={!$Request.retURL}'; 

 

 

All Answers

bob_buzzardbob_buzzard

Does the account in question have a single quote in the name?  If so, in the following code, the inclusion of the account name merge field will terminate the string:

 

 

else 
parent.location.href = '/apex/TRGContactEdit?con4_lkid={!Account.Id}&con4={! Account.Name}&RecordTypeId={!Contact.RecordTypeId}&retURL={!$Request.retURL}'; 

 

 

This was selected as the best answer
SanchSanch

Yes...That was the issue. Thank you so much.

 

Sanch.