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
cmarkcmark 

parameters in URLFOR...

Hello.  I am writing an scontrol which overrides the New button on a Custom Object.   I want the button to take me to an edit screen, but I want to pass a few parameters.  I'm able to pass constant string parameters into fields, but I can't make dynamic fields work.  My basic scontrol is pasted below.  The "static text here" is displayed in the input field in the edit screen.  However I can't make the Project__c.Name value appear.  I've tried all sorts of things - enclosing it in quotes (then the quoted text appears), using the merge notation (error when saving), etc.

Note that I'm trying to create a new Timecard__c record from inside the Project__c record's related list.  (If using the New button from anywhere else, these fields will be blank which is fine...)  So my question is - what is the proper notation that I use to pass the value of Project__c.Name?

<script type="text/javascript">
window.parent.location.href="{! URLFOR($Action.Timecard__c.New, null, [CF00N50000001S4Rz="static text here", CF00N50000001Ru1r=Project__c.Name], true)}";
</script>

Thanks for your time.

Chris


igoruigoru
CF00N50000001S4Rz="static text here",F00N50000001Ru1r=Project__c.Name
 
 
Hi!
instead "Project__c.Name" - you can fill it value in controller variable & use it successfully in URLFOR
 
:smileyhappy:
 
With best wishes,
                               Igor
LalitLalit
Please let me know if you found a solution for the below issue, how to pass Parameter in URLFOR, I also need to pass the ID of previous page as default value for one of the field
jeremyajohnsonjeremyajohnson
I am also looking for an answer to this question.
PerGeert-tooPerGeert-too

Find the ID of the parameters - in my example two lookup fields.

Make a VF page like this:

 

<apex:page standardController="OwnEquipment__c" extensions="OwnEquipmentControllerExt"
	action="{!URLFOR($Action.OwnEquipment__c.New,null,
	[CF00N40000001TxNz=OwnerName,CF00N40000001TxNz_lkid=OwnerId,
	 CF00N40000001U25l=ContactName,CF00N40000001U25l_lkid=ContactId],true )}"/>

 

and a controller extension like this:

 

public class OwnEquipmentControllerExt {
	
    public OwnEquipmentControllerExt(ApexPages.StandardController controller) {
		acct = getAccount();
	}	
	
	public string getOwnerName() {
		if (acct == null) {return '';} else {return acct.name;}
	}
	
	public string getOwnerId() {
		if (acct == null) {return '';} else {return acct.id;}
	}
	
	public string getContactName() {
		return UserInfo.getName();
	}
	
	public string getContactId() {
		return UserInfo.getUserId();
	}
	
	private Account acct = null;
	private Account getAccount() {
		integer no = [select count() from Account where backofficeId__c like '%Remarketed'];
		if (no != 1) return null;
		acct = [select id, name from Account where backofficeId__c like '%Remarketed' limit 1];
		return acct;
	}
}

 Finally, overwrite the New button for the opbject (in my example OwnEquipment__c).

PerGeert-tooPerGeert-too

I did some fine-tuning to the example above:

 

 

<apex:page standardController="OwnEquipment__c" extensions="OwnEquipmentControllerExt"
    action="{!URLFOR($Action.OwnEquipment__c.New,null,
    [CF00N40000001TxNz=OwnerName,CF00N40000001TxNz_lkid=OwnerId,
     CF00N40000001U25l=ContactName,CF00N40000001U25l_lkid=ContactId,
     retURL=RetUrl],true )}"/>

 

public with sharing class OwnEquipmentControllerExt {
	
	private string pretUrl = null;
	private string pOwnerName = null;
	private string pOwnerId = null;
	
    public OwnEquipmentControllerExt(ApexPages.StandardController controller) {
    	// Get any supplied parameters
		PageReference pageRef = ApexPages.currentPage();
        Map<String, String> pageParameters = pageRef.getParameters();
        
        pretUrl = pageParameters.get('retURL');
        pOwnerName = pageParameters.get('CF00N40000001TxNz');
        pOwnerId = pageParameters.get('CF00N40000001TxNz_lkid');
        
		if (pOwnerName == null) getAccount();
	}	
	public string getRetUrl() {
		return pretUrl;
	}
	
	public string getOwnerName() {
		return pOwnerName;
	}
	
	public string getOwnerId() {
		return pOwnerId;
	}
	
	public string getContactName() {
		return UserInfo.getName();
	}
	
	public string getContactId() {
		return UserInfo.getUserId();
	}
	
	private Account acct = null;
	private void getAccount() {
		// If account paramters weren't supplied, get an account
		integer no = [select count() from Account where backofficeId__c like '%Remarketed'];
		if (no != 1) return;
		
		// If there is only one possibility, get that one
		acct = [select id, name from Account where backofficeId__c like '%Remarketed' limit 1];
		pOwnerName = acct.name;
		pOwnerId = acct.id;
		return;
	}
	
	static testmethod void testit() {
		OwnEquipment__c oe = new OwnEquipment__c();
		ApexPages.StandardController sc = new ApexPages.StandardController(oe);
		OwnEquipmentControllerExt controller = new OwnEquipmentControllerExt(sc);
		
		controller.getOwnerName();
		controller.getOwnerId();
		controller.getContactName();
		controller.getContactId();
		controller.getRetUrl();			
	}
}

 

 

Eric_SantiagoEric_Santiago

Is there a way to do this where you don't hardcode the field id's ? Like $field.id versus CF00N40000001TxNz ? Its hard to hardcode these ids and then deploy the code to other orgs.