5

I am using the new (Spring '20) Lightning URL hack functionality. This is the URL that I have constructed so far, it is invoked by a detail page button on the Opportunity object:

/lightning/o/Quote/new?defaultFieldValues=Name={!URLENCODE(Opportunity.Name)},
OpportunityId={!Opportunity.Id},
ExpirationDate={!TEXT(Opportunity.CloseDate)},
ContactId={!Opportunity.ContactpersoonId__c}

It works perfectly, as long as all those Opportunity fields have values. But I have Opportunities for which Contactpersoon__c, hence also ContactpersoonId__c, is empty. When clicking the custom button, Salesforce complains:

Looks like there's a problem.

Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. Error ID: 1031679058-169998 (-1922518417)

With Classic URL hacks, empty fields were no problem. How do I deal with them under Lightning?

10
  • Is it stored as a link? From where are you invoking it?
    – manjit5190
    Mar 26, 2020 at 16:42
  • Maybe create a dummy contact person that you only ever pass in if that field should be blank. If the field is that id, then in a process or workflow, clear it. Mar 30, 2020 at 6:43
  • @CasparHarmer I was actually thinking of the opposite: remove it from the URL and have a trigger/workflow/process fill the field after creation. Though this is a bit confusing, as the user will see an empty field on the creation window. Mar 30, 2020 at 6:58
  • Have you investigated setting a different record type to change the new record ui? And then setting back to regular record type after creation? Mar 30, 2020 at 7:02
  • 1
    If you add a Quote record type, you could make 2 versions of the new Quote layout, one without the unwanted field and one with it. Then depending on the record type you set, different "New Quote" layouts would appear on record creation... I think. Mar 30, 2020 at 8:51

2 Answers 2

7

After more googling, it looked as if URLFOR expressions were also valid for use in Lightning URL hacks. That opened up a whole new set of potential solutions. After much experimentation, I came upon the following:

{!URLFOR( '/lightning/o/Quote/new?defaultFieldValues=Name=' + 
URLENCODE(Opportunity.Name) + ',OpportunityId=' + Opportunity.Id + 
',ExpirationDate=' + TEXT(Opportunity.CloseDate) + 
IF(ISBLANK(Opportunity.ContactpersoonId__c), '', ',ContactId=' + Opportunity.ContactpersoonId__c) )}

This works for opportunities with and without a filled ContactpersoonId__c field, so it solves my problem.

0

It is also possible to use the IF statement inside the URL Hack without using URLFOR. In the following example, the IF statement encompasses everything regarding Field3, both before and after the equal sign, so if Object1__c.Field8__c='', then not even ',Field3=' will appear in the URL:

/lightning/o/Case/new?useRecordTypeCheck=1&defaultFieldValues=
Field1__c={!Object1__c.Field2__c},
Field2={!Object__1.Id}
{!IF(Object1__c.Field8__c='','',',Field3=' +Object1__c.Field8__c)}

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.