-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get correct compact layout for sObject #53
Conversation
export interface CompactLayoutField { | ||
editableForNew: boolean; | ||
editableForUpdate: boolean; | ||
label: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbreese We don't have to use this interface. I added so that I can cast to this before returning to the caller so LWC generating code can have defined fields in the elements of returned array of sObject's fields. Otherwise, you might need to do lot of casting as I do in getCompactLayoutFieldsForSObject
.
src/utils/orgUtils.ts
Outdated
public static async getAllCompactLayoutsForSObject( | ||
sObjectName: string | ||
): Promise<any> { | ||
const org = await Org.create(); | ||
const conn = org.getConnection(); | ||
|
||
const result = await conn.request( | ||
`/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts` | ||
); | ||
|
||
return Promise.resolve(result); | ||
} | ||
|
||
public static async getCompactLayoutForSObject( | ||
sObjectName: string, | ||
recordTypeId: string | ||
): Promise<any> { | ||
const org = await Org.create(); | ||
const conn = org.getConnection(); | ||
|
||
const result = await conn.request( | ||
`/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts/${recordTypeId}` | ||
); | ||
|
||
return Promise.resolve(result); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wrapping conn.request
because request
method of Connection
returns StreamResult
. StreamResult
is a type from @salesforce/core
API and I couldn't find a way to create it or use it. Worse, Typescript was very strict when I tried to create stubs using sinon. So I wrapped them in methods and this way I can wrap the wrapping methods in the unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it returns a StreamPromise
from some version of the jsforce
package—which is just an extension of Promise
that has some stream-specific functions added.
But I think it's fine you're doing it this way, in any case. As I mentioned below, I would change the type to Promise<Object>
, and coerce that type as necessary.
If we wanted to get fancy at some point, the request
method takes a template type, so we could be more definitive in specifying what we want to return, for example:
const result: Promise<OurStronglyTypedCompactLayoutResultType> =
await conn.request<OurStronglyTypedCompactLayoutResultType>(
`/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts/${recordTypeId}`
);
return Promise.resolve(result);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using Promise<Object>
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sfdctaka ! This is looking like a great first pass! 👍
a83af4a
to
d62c587
Compare
To get a compact layout for a sObject I am using 2-pass process.
If sObject has compact layout assigned it will have
defaultCompactLayoutId
assigned. Otherwise,null
is assigned and in that case the compact layout is defaults toSYSTEM
compact layout.After determining which compact layout is actually needed only after that a second network request need to be made in order to get the actual layout content.