528
edits
No edit summary |
No edit summary |
||
Line 35: | Line 35: | ||
* You have access to "element", "documentData", "contextObject" and the function "callout" | * You have access to "element", "documentData", "contextObject" and the function "callout" | ||
<syntaxhighlight lang="javascript" line="1"> | <syntaxhighlight lang="javascript" line="1"> | ||
//Wrapper element which will be inserted in the document at requested index | async (args) => { | ||
//Wrapper element which will be inserted in the document at requested index | |||
//An object that is populated with all the data loaded from the server | let element = args[0]; | ||
//An object that is populated with all the data loaded from the server | |||
//The contextual record where the Function Expression is placed in | let documentData = args[1]; | ||
//The contextual record where the Function Expression is placed in | |||
let contextObject = args[2]; | |||
//Server communication class | |||
let callout = args[3]; | |||
// | //Always return a string that will be inserted in the document | ||
return ''; | |||
} | |||
} | |||
</syntaxhighlight>''Note: The "contextObject" is the document's "Core Object" record. If the function expression is embedded in a child repeatable context, then the contextObject becomes the child record.'' | </syntaxhighlight>''Note: The "contextObject" is the document's "Core Object" record. If the function expression is embedded in a child repeatable context, then the contextObject becomes the child record.'' | ||
Line 111: | Line 107: | ||
=== Javascript === | === Javascript === | ||
Now that you have the APEX class created successfully, you are ready to call it from within a function expression. Here is an example of how to call our sample class<syntaxhighlight lang="javascript"> | Now that you have the APEX class created successfully, you are ready to call it from within a function expression. Here is an example of how to call our sample class<syntaxhighlight lang="javascript"> | ||
callout({ | const response = await callout({ | ||
endp: | endp: "classMethodName", | ||
...// additional parameters | |||
}, | |||
false,//Use REST or AJAX | |||
} | "ApexClassName" | ||
); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 139: | Line 135: | ||
=== Embed Charts === | === Embed Charts === | ||
This example demonstrates how we can embed highcharts into a template. This example uses static data, but you can route with data from the template.<syntaxhighlight lang="javascript" line="1" start="1"> | This example demonstrates how we can embed highcharts into a template. This example uses static data, but you can route with data from the template.<syntaxhighlight lang="javascript" line="1" start="1"> | ||
async (args) => { | |||
let element = args[0]; | |||
let documentData = args[1]; | |||
let contextObject = args[2]; | |||
let callout = args[3]; | |||
const reportData = | const reportData = await callout({ | ||
await callout({ | endp: 'getReportData' | ||
},'FunctionExpressions'); | |||
},'FunctionExpressions' | |||
var script = document.createElement('script'); | var script = document.createElement('script'); | ||
script.src = 'https://code.highcharts.com/highcharts.js'; | script.src = 'https://code.highcharts.com/highcharts.js'; | ||
document.head.appendChild(script); | document.head.appendChild(script); | ||
let customId = Math.random().toString(36).slice(2, 7); | |||
let chartWrapper = document.createElement('div'); | |||
chartWrapper.id = customId; | |||
element.after(chartWrapper); | |||
script.onload = function () { | |||
//Implement highcharts loading | |||
element.appendChild(...); | |||
}; | |||
//Return an empty string | |||
script.onload = function () { | return ''; | ||
} | |||
}; | |||
return ''; | |||
</syntaxhighlight> | </syntaxhighlight> | ||