diff --git a/src/commands/force/mdapi/listmetadata.ts b/src/commands/force/mdapi/listmetadata.ts index cd1b1cbc1..0f8a22f5c 100644 --- a/src/commands/force/mdapi/listmetadata.ts +++ b/src/commands/force/mdapi/listmetadata.ts @@ -68,7 +68,10 @@ export class ListMetadata extends SourceCommand { this.validateResultFile(); - const query: ListMetadataQuery = { type, folder }; + const query: ListMetadataQuery = { type }; + if (folder) { + query.folder = folder; + } const connection = this.org.getConnection(); const result = (await connection.metadata.list(query, apiversion)) || []; this.listResult = Array.isArray(result) ? result : [result]; diff --git a/test/nuts/mdapi.nut.ts b/test/nuts/mdapi.nut.ts index 820c2b3e3..19582ba1d 100644 --- a/test/nuts/mdapi.nut.ts +++ b/test/nuts/mdapi.nut.ts @@ -49,12 +49,22 @@ describe('mdapi NUTs', () => { }); describe('mdapi:listmetadata', () => { - it('should successfully execute listmetadata', () => { + it('should successfully execute listmetadata for type CustomObject', () => { const result = execCmd('force:mdapi:listmetadata --json --metadatatype CustomObject'); expect(result.jsonOutput.status).to.equal(0); expect(result.jsonOutput.result).to.be.an('array').with.length.greaterThan(100); expect(result.jsonOutput.result[0]).to.have.property('type', 'CustomObject'); }); + + it('should successfully execute listmetadata for type ListView', () => { + // ListView is sensitive to how the connection.metadata.list() call is made. + // e.g., if you pass { type: 'ListView', folder: undefined } it will not return + // any ListViews but if you pass { type: 'ListView' } it returns all ListViews. + const result = execCmd('force:mdapi:listmetadata --json --metadatatype ListView'); + expect(result.jsonOutput.status).to.equal(0); + expect(result.jsonOutput.result).to.be.an('array').with.length.greaterThan(10); + expect(result.jsonOutput.result[0]).to.have.property('type', 'ListView'); + }); }); describe('mdapi:describemetadata', () => {