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 content on standard new/edit page for accounts

Hi,

 

I tried googling around, but I couldn't really find what I am looking for. What are currently the options of changing the behaviour and content of standard (new/edit) pages? See below for the scenario I would like to create.

 

I would like to create address lookup based on postcode details. For this I would like to modify existing pages for accounts.So I created a sidebar component and added some javasript to modify the components. Unfortunately, when deploying to sandbox I found out that it will not work, because different server addresses for the visual force servers

 

[code]

window.parent.document.getElementById('acc17country')

[/code]

 

Since the account has a lot of fields I don't really like to go into the way of full recreate the new/edit pages with a new visual force page.

 

So I am looking for ways to modify the content, I know there are some things possible like adding a (floatable) picklist for the countries in this app CountryCompleteFree. But I cannot really understand how they are doing this. Any help will be appreciated.

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I think you'll find this is done using an HTML area sidebar component that executes some javascript from a static resource file - that's how other address lookups I've seen worked.

All Answers

bob_buzzardbob_buzzard

I think you'll find this is done using an HTML area sidebar component that executes some javascript from a static resource file - that's how other address lookups I've seen worked.

This was selected as the best answer
JeeedeeeJeeedeee

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/

 

 

 

nasknask

i have added a custom javascript component to home page side bar. But if i add this then i cant hide the side bar if open or open if its closed. And even my inline editing properrty is also not working? have you seen any thing like this before?

geFrankgeFrank

This is great, thank you for posting this!

Force.comForce.com

Thanks schreurs_id, Your post helped me a lot.

nasknask

HI did it not break your  inline editing fucntionality.?

Force.comForce.com

Hi Bob,

 

My requirement is to hide the standard account field from record detail page. So taking help from this post, I created a visualforce page and embedded it in the account record detail page.

 

To hide the standard Billing address field from account object, I tried the below code

 

<apex:page standardController="Account">
<script src="/js/dojo/0.4.1/dojo.js"></script>
<script src="/soap/ajax/11.1/connection.js" type="text/javascript"></script>
<script type="text/javascript">
dojo.require("dojo.collections.Store");
dojo.require("dojo.charting.Chart");
dojo.require('dojo.json');

alert('test1');


if(document.getElementById('acc17_ilecell') != null) {
alert('test2');
var select = document.getElementById('acc17_ilecell');
var curValue = select.value;
alert('curValue '+curValue );
var parentx = select.parentNode;
parentx.removeChild(select);
select = document.createElement('select');
select.size = 1;
select.id = 'acc17_ilecell';
// select.name = 'acc17_ilecell';
parentx.appendChild(select);
alert('test');
}

</script>
</apex:page>

 

However, the control is failed to enter inside if block. I am not sure why. Please help.

 

Thanks,

Pragati