Skip to main content

Save/cancel on standard edit button returns user to the same context that they started from.  So if they started on a list view, they return to that list view.

 

If you override edit with LWC, is there a supported way to know the context where a user is clicking edit so we can return them to the right place?

  • are they coming from a list view row (and if so which list view) 
  • are clicking the edit button on the record
  • are they clicking edit from a related list on a parent record

Are there standard parameters that salesforce provides to a custom component that overrides edit?   Our devs were able to get context by base64decoding the "inContextOfRef" that is passed to the component.  I cant find any documentation about it though.   Is this supported or documented anywhere?  

 

Without this ability, edit override with LWC will have significant limitations.

 

thanks!

1 resposta
  1. 3 de dez. de 2023, 14:16

    Yes! There is!

     

    First let's take a look in the url after you click in an actionOverrided button

     

    /new?inContextOfRef=1.eyJ0eXBlIjoic3RhbmRhcmRfX29iamVjdFBhZ2UiLCJhdHRyaWJ1dGVzIjp7Im9iamVjdEFwaU5hbWUiOiJNeU9iamVjdF9fYyIsImFjdGlvbk5hbWUiOiJsaXN0In0sInN0YXRlIjp7ImZpbHRlck5hbWUiOiJSZWNlbnQifX0%3D&count=1

    This url tells you something. If you look it thoroughly, you'll notice it has this pattern 

    /new?inContextOfRef=1.{{base64_url_encoded}}&count=1

    It's "something" that was first base64 encoded, then url encoded.

     

    So you just need to get this "something" (i.e. the {{base64_url_encoded}}) and:

    • url decode it
    • base 64 decode it

    You will find the following

    {"type":"standard__objectPage","attributes":{"objectApiName":"MyObject__c","actionName":"list"},"state":{"filterName":"Recent"}}

    This is it! Now you have a json with all the context you need.

     

    I hope this helps.