mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #50220 Add 'search' method to connection.js by @douglascayers
* add 'search' method * add 'search' tests Co-authored-by: trailhead-content-bot <trailhead_content_publish_toolchain@salesforce.com>
This commit is contained in:
5
types/jsforce/connection.d.ts
vendored
5
types/jsforce/connection.d.ts
vendored
@@ -153,6 +153,10 @@ export interface ExecuteAnonymousResult {
|
||||
|
||||
export type ConnectionEvent = "refresh";
|
||||
|
||||
export interface SearchResult<T> {
|
||||
searchRecords: Record<T>[];
|
||||
}
|
||||
|
||||
/**
|
||||
* the methods exposed here are done so that a client can use 'declaration augmentation' to get intellisense on their own projects.
|
||||
* for example, given a type
|
||||
@@ -217,6 +221,7 @@ export abstract class BaseConnection extends EventEmitter {
|
||||
recent(callback?: (err: Error, result: RecordResult[]) => void): Promise<(RecordResult[])>;
|
||||
recent(param: number | string, callback?: (err: Error, result: RecordResult[]) => void): Promise<(RecordResult[])>;
|
||||
recent(type: string, limit: number, callback?: (err: Error, result: RecordResult[]) => void): Promise<(RecordResult[])>;
|
||||
search<T>(sosl: string, callback?: (err: Error, result: SearchResult<T>) => void): Promise<(SearchResult<T>)>;
|
||||
}
|
||||
|
||||
export class Connection extends BaseConnection {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { RecordReference, Record } from 'jsforce/record';
|
||||
import { SObject } from 'jsforce/salesforce-object';
|
||||
import { RecordResult } from 'jsforce/record-result';
|
||||
import { BatchDescribeSObjectOptions, DescribeSObjectOptions, DescribeSObjectResult } from 'jsforce/describe-result';
|
||||
import { SearchResult } from 'jsforce/connection';
|
||||
|
||||
const salesforceConnection: sf.Connection = new sf.Connection({
|
||||
instanceUrl: '',
|
||||
@@ -467,6 +468,10 @@ const requestInfo: sf.RequestInfo = {
|
||||
interface MyFoo {
|
||||
anything: string;
|
||||
}
|
||||
interface MyBar {
|
||||
something: string;
|
||||
}
|
||||
|
||||
salesforceConnection.request<MyFoo>(requestInfo).then((myFoo: MyFoo) => {
|
||||
console.log(myFoo.anything)
|
||||
});
|
||||
@@ -501,6 +506,20 @@ salesforceConnection.query('SELECT Id FROM Account')
|
||||
})
|
||||
.run({ autoFetch: true, maxFetch: 25 });
|
||||
|
||||
salesforceConnection.search<MyFoo|MyBar>('FIND {my} IN ALL FIELDS RETURNING Foo__c(Id, Name), Bar__c(Id, Name)', (err: Error, result: SearchResult<MyFoo|MyBar>) => {
|
||||
console.error(err);
|
||||
for (const record of result.searchRecords) {
|
||||
if (record && record.attributes && record.attributes.type === 'Foo__c') {
|
||||
const foo = record as MyFoo;
|
||||
console.log(foo.anything);
|
||||
}
|
||||
if (record && record.attributes && record.attributes.type === 'Bar__c') {
|
||||
const bar = record as MyBar;
|
||||
console.log(bar.something);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
salesforceConnection.sobject<any>('Coverage__c')
|
||||
.select(['Id', 'Name']).del(() => { });
|
||||
|
||||
|
||||
10
types/jsforce/record.d.ts
vendored
10
types/jsforce/record.d.ts
vendored
@@ -15,4 +15,12 @@ export class RecordReference<T = any> {
|
||||
update(record: Partial<T>, options?: Object, callback?: (err: Error, result: RecordResult) => void): Promise<RecordResult>;
|
||||
}
|
||||
|
||||
export type Record<T = any> = { Id?: SalesforceId } & T;
|
||||
export interface RecordAttributes {
|
||||
type: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export type Record<T = any> = {
|
||||
Id?: SalesforceId;
|
||||
attributes?: RecordAttributes
|
||||
} & T;
|
||||
|
||||
Reference in New Issue
Block a user