3

Could someone please review the following code and explain why this custom button is not working?

<apex:page action="{!urlFor('/a0H/e?
Name=[autoname]
&CF00N3B000000TB2z={!Contact.Name}
&CF00N3B000000TB2z_lkid={!Contact.Id}
&retURL=%2F{!Contact.ID}')}" 
standardController="Service__c"/>

BACKGROUND: We are overriding the standard "new" button via this VF page. It should populate the new record being created by putting "[autoname]" in the Name field (this part is working just fine, btw) AND pre-populate a lookup field with the Contact's name. This later component is what we are experiencing problems with. The new Service record should be created from a Contact record's related list button (i.e., from the Service related list).


BREAKDOWN:

a0H - reference to our custom object named Service__c.

Name - required name field for a new Service__c record. We want the value [autoname] to pre-populate so upon saving a workflow renames the record with a standardized naming convention.

CF00N3B000000TB2z - id of the lookup field we are trying to pre-populate on the new Service record. We are tyring to pass the full name of the Contact here.

CF00N3B000000TB2z_lkid - id of the lookup field we are trying to prepopulate on the new Service record. We are trying to pass the Contact Id here.

Here is the URL when seen on the opened page:

https://c.cs50.visual.force.com/apex/NEW_SERVICE?+Name=%5Bautoname%5D+&CF00N3B000000TB2z=&save_new=1&sfdc.override=1#{Contact.Name}&CF00N3B000000TB2z_lkid={!Contact.Id}&retURL=%2F{!Contact.ID}
  • so, what does the URL look like in the address bar when the page is opened? – cropredy Dec 16 '15 at 20:54
  • c.cs50.visual.force.com/apex/…{Contact.Name} &CF00N3B000000TB2z_lkid={!Contact.Id} &retURL=%2F{!Contact.ID} – Jake Schmitz Dec 16 '15 at 20:58
  • I updated your post with the full URL -- please check it and verify it is exactly what you see in the browser as there were embedded spaces in what you commented. Use the Edit link in the OP – cropredy Dec 16 '15 at 21:05
0

You're trying to reference Contact, bu the system doesn't know what contact you're talking about. Here's how I'd write this (assuming the related contact field is called Contact__c):

<apex:page
    action="{!URLFOR($Action.Service__c.Edit, Service__c.Id,
        [id=Service__c.Id, CF00N3B000000TB2z=Service__c.Contact__r.Name,
         CF00N3B000000TB2z_lkid=Service__c.Contact__c,
         retURL='/'&Service__c.Contact__c])}"
    standardController="Service__c" />
  • I forgot to specify: the new Service record is being created FROM a Contact record's related list (i.e. "Service" related list). Sorry for leaving out this detail... – Jake Schmitz Dec 16 '15 at 20:00
  • Thanks for the sample code @sfdcfox However, I get an "Invalid parameter for function URLFOR" error – Jake Schmitz Dec 16 '15 at 21:23

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.