0

I have created a custom button Type=DetailPage & Content=URL on the Event Object. This button creates a new Custom Object named Registration record. One of the fields that needs to be set on the Registration record during creation is a date field (there are actually 2 date fields) and that needs to be set from the Events custom Date field. I have it working, in regards to populating the data in the Registration fields BUT..when trying to Save it gives and error as if it doesn't realize it's there. Once you click into the fields, it satisfies the validation. Not sure if it's something in my syntax. Here are the button details, with the 2 date field lines highlighted: enter image description here

And here is what the New Registration screen looks like after clicking Save and using the custom button: enter image description here

Would anyone have any suggestions on how to correct this?

4
  • 2
    Hi please check this github.com/trailheadapps/lwc-recipes/tree/main/force-app/main/… . you should use navigation this URL hack is not a good idea to start Commented Mar 27, 2023 at 21:23
  • did you try: End__c={!DATEVALUE(Event.EndDateTime)} ?
    – cropredy
    Commented Mar 27, 2023 at 21:37
  • @cropredy : I did replace my line End__c={!URLENCODE(TEXT(Event.EndDateTime))}, with yours End__c={!DATEVALUE(Event.EndDateTime)} but I still get the validation error saying that End Date needs to be populated even though it is
    – user7417
    Commented Mar 29, 2023 at 15:11
  • @Avijit Chakraborty: I understand the URL hacks are not a good idea but I needed to replace an existing button that was a Classic URL hack during a lightning migration project I am working on. Someone previously (long gone) created it and I just wanted to quickly replicate something that was supported in Lightning. I am not a developer so I am limited on what I can do. I'm not sure what the link to github could do for me? I'm unsure how to use that info.
    – user7417
    Commented Mar 29, 2023 at 15:16

1 Answer 1

2
+50

When using {!URLENCODE(TEXT(Event.EndDateTime))}, the time value is being sent "silently" to the date field, hence the validation error even though visually the only date portion is visible. You can try the formula into a text field to see this.

Note that {!URLENCODE(TEXT(Event.EndDateTime))} can cause incorrect date formatting when passing value to date field.

To fix your issue use this formula by converting to date first:

End__c={!URLENCODE(TEXT(DATEVALUE(Event.EndDateTime)))},

3
  • are you saying I need to create a new formula field and use that new field to populate the date on the new record?
    – user7417
    Commented Apr 3, 2023 at 12:47
  • @user7417 no need to create a new formula field. in your existing custom url formula, just replace formula with the fix provided in answer for end__c and start__c accordingly
    – Shamina
    Commented Apr 3, 2023 at 14:03
  • 1
    That was it, thanks! So I needed the additional "DATEVALUE" in my formula. All good info to know. Thanks you so much for getting me over the finish line with this.
    – user7417
    Commented Apr 3, 2023 at 15:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .