function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JeeedeeeJeeedeee 

Modify existing pages

In apps like Postcode Anywhere they change the standard account page, and adding links like "Clear Billing, Clear Shipping and find" behind de postal code, and changing country list into picklist. See this picture

 

 

How do they do that? It's without a visual force page. I try to make something like this, with a custom home page component and javascript. But I keep having troubles with the cross domain security issue. Even hosting the javascript code in an static resource is not working.

 

It is getting to drive me completely crazy now... Any tips would be really welcome, since I am out of options now.

Best Answer chosen by Admin (Salesforce Developers) 
JeeedeeeJeeedeee

Jim,

 

Thanks for your idea, looked into it, and finally I found a solution by using a custom component and javascript.

 

For more details take a look at this post

http://community.salesforce.com/t5/Visualforce-Development/Modify-content-on-standard-new-edit-page-for-accounts/td-p/196319

Bob thanks a lot, you made me think again and I have solved the problem now. It makes me so happy, and that before the weekend :)Below a part of my solution, but I feel that the use of component and HTML/javascript in there feels a bit like a hack. I wonder how long Salesforce still allows this functionality. 

 

 For everybody who's interested. Here is what I did to transfer the standard country field into a picklist rather than a text field on standard account page.Next step for me is adding input fields so I can build postcode lookup :)

 

1) Enable the following setting: Go to Setup -> Customize -> User Interface -> Show Custom Sidebar Components on All Pages

2) Create a new home page component and add it to the narrow home page layout.

<script src="/js/dojo/0.4.1/dojo.js"></script>
<script src="/soap/ajax/19.0/connection.js" type="text/javascript"></script>
<script src="/resource/1280482442000/updatezip2" type="text/javascript"></script>
<script type="text/javascript">
dojo.require("dojo.collections.Store");
dojo.require("dojo.charting.Chart");
dojo.require('dojo.json');
dojo.addOnLoad(swapCountryText);
</script>

3) Upload the static resource with the javasript which can modify the page

 

var arCountries;
function swapCountryText(){
// Account Billing Address
if(document.getElementById('acc17country') != null) {
loadCountries();
var select = document.getElementById('acc17country');
var curValue = select.value;
var parentx = select.parentNode;
parentx.removeChild(select);
select = document.createElement('select');
select.size = 1;
select.id = 'acc17country';
select.name = 'acc17country';
parentx.appendChild(select);
}

// Account Shipping Address
if(document.getElementById('acc18country') != null) {
loadCountries();
var select2 = document.getElementById('acc18country');
var curValue2 = select2.value;
var parenty = select2.parentNode;
parenty.removeChild(select2);
select2 = document.createElement('select');
select2.size = 1;
select2.id = 'acc18country';
select2.name = 'acc18country';
parenty.appendChild(select2);
}
if(select != null) {
if(arCountries.length>0) {
for(x=0;x<arCountries.length;x++) {
if(arCountries[x] == curValue) {
select.options[x] = new Option(arCountries[x], arCountries[x], false, true);
} else {
select.options[x] = new Option(arCountries[x], arCountries[x], false, false);
}
}
} else {
select.options[x] = new Option('No countries found', 'No countries found', false, true);
}
}
if(select2 != null) {
if(arCountries.length>0) {
for(x=0;x < arCountries.length;x++) {
if(arCountries[x] == curValue2) {
select2.options[x] = new Option(arCountries[x], arCountries[x], false, true);
} else {
select2.options[x] = new Option(arCountries[x], arCountries[x], false, false);
}
}
} else {
select2.options[x] = new Option('No countries found', 'No countries found', false, true);
}
}
}

function loadCountries() {
if(arCountries == null) {
arCountries = getCountries();
}
}

function getCountries() {
sforce.sessionId = getCookie('sid');
sforce.connection.sessionId=sforce.sessionId;
var out = [];
try {
var queryCountries = sforce.connection.query("Select Id, Name FROM Country__c ORDER BY Name");
var countries = queryCountries.getArray('records');
for(x=0;x<countries.length;x++) {
out[out.length] = countries[x].Name;

}

} catch(error) {
alert(error);
}
return out;
}

 ps: thanks to Harm Korten which supplies most of this code http://salesforce.harmkorten.nl/2010/salesforce-country-fields-as-picklists/



 

All Answers

gv007gv007

Schreurs,

                 I am not sure it is right solution or not but trying is harm

 

make a section like addrees:

in this selection use a inline VF page

in the VF page use yours java script

 

please let us know if you find any good idea

JeeedeeeJeeedeee

Hi Gopi,

 

Thanks, I tried your scenario. I created a new page with an account controller. I added this to both detail and edit page(section settings) of the account layout. BUT, what I was afraid off happened. It didn't showed up on both new and/or edit page for some reason :smileysad:

 

<apex:page showHeader="false" sidebar="false" standardController="Account">
  Test if I can add this to edit page, unfortunately not ...
</apex:page>

 

 

JimRaeJimRae

My guess is that they are injecting some type of style sheet (CSS) to change the way the default page get's rendered.  Not that I know how to do that, but I have heard of applications doing that.

 

 

JeeedeeeJeeedeee

Jim,

 

Thanks for your idea, looked into it, and finally I found a solution by using a custom component and javascript.

 

For more details take a look at this post

http://community.salesforce.com/t5/Visualforce-Development/Modify-content-on-standard-new-edit-page-for-accounts/td-p/196319

Bob thanks a lot, you made me think again and I have solved the problem now. It makes me so happy, and that before the weekend :)Below a part of my solution, but I feel that the use of component and HTML/javascript in there feels a bit like a hack. I wonder how long Salesforce still allows this functionality. 

 

 For everybody who's interested. Here is what I did to transfer the standard country field into a picklist rather than a text field on standard account page.Next step for me is adding input fields so I can build postcode lookup :)

 

1) Enable the following setting: Go to Setup -> Customize -> User Interface -> Show Custom Sidebar Components on All Pages

2) Create a new home page component and add it to the narrow home page layout.

<script src="/js/dojo/0.4.1/dojo.js"></script>
<script src="/soap/ajax/19.0/connection.js" type="text/javascript"></script>
<script src="/resource/1280482442000/updatezip2" type="text/javascript"></script>
<script type="text/javascript">
dojo.require("dojo.collections.Store");
dojo.require("dojo.charting.Chart");
dojo.require('dojo.json');
dojo.addOnLoad(swapCountryText);
</script>

3) Upload the static resource with the javasript which can modify the page

 

var arCountries;
function swapCountryText(){
// Account Billing Address
if(document.getElementById('acc17country') != null) {
loadCountries();
var select = document.getElementById('acc17country');
var curValue = select.value;
var parentx = select.parentNode;
parentx.removeChild(select);
select = document.createElement('select');
select.size = 1;
select.id = 'acc17country';
select.name = 'acc17country';
parentx.appendChild(select);
}

// Account Shipping Address
if(document.getElementById('acc18country') != null) {
loadCountries();
var select2 = document.getElementById('acc18country');
var curValue2 = select2.value;
var parenty = select2.parentNode;
parenty.removeChild(select2);
select2 = document.createElement('select');
select2.size = 1;
select2.id = 'acc18country';
select2.name = 'acc18country';
parenty.appendChild(select2);
}
if(select != null) {
if(arCountries.length>0) {
for(x=0;x<arCountries.length;x++) {
if(arCountries[x] == curValue) {
select.options[x] = new Option(arCountries[x], arCountries[x], false, true);
} else {
select.options[x] = new Option(arCountries[x], arCountries[x], false, false);
}
}
} else {
select.options[x] = new Option('No countries found', 'No countries found', false, true);
}
}
if(select2 != null) {
if(arCountries.length>0) {
for(x=0;x < arCountries.length;x++) {
if(arCountries[x] == curValue2) {
select2.options[x] = new Option(arCountries[x], arCountries[x], false, true);
} else {
select2.options[x] = new Option(arCountries[x], arCountries[x], false, false);
}
}
} else {
select2.options[x] = new Option('No countries found', 'No countries found', false, true);
}
}
}

function loadCountries() {
if(arCountries == null) {
arCountries = getCountries();
}
}

function getCountries() {
sforce.sessionId = getCookie('sid');
sforce.connection.sessionId=sforce.sessionId;
var out = [];
try {
var queryCountries = sforce.connection.query("Select Id, Name FROM Country__c ORDER BY Name");
var countries = queryCountries.getArray('records');
for(x=0;x<countries.length;x++) {
out[out.length] = countries[x].Name;

}

} catch(error) {
alert(error);
}
return out;
}

 ps: thanks to Harm Korten which supplies most of this code http://salesforce.harmkorten.nl/2010/salesforce-country-fields-as-picklists/



 

This was selected as the best answer