-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
2Questions
-
2Replies
Page Context in Background Utility Item
I created a Background Utility Item component that uses empApi component to listen on capture data change. I need to have it aware of Page Context and able to get record id of current page. I tried to use force:hasRecordId interface with component.get("v.recordId") but it doesn't works. If I remove the lightning:backgroundUtilityItem interface and use it in Utility Bar, I am able to retrieve the record id. Do you know if it is by design or an issue from Salesforce ? Do you have any workaround ?
Thank you
Thank you
<aura:component implements="flexipage:availableForAllPageTypes,lightning:backgroundUtilityItem,force:hasRecordId" access="global">
<aura:attribute name="channel" type="String" required="true" default="/data/ChangeEvents" />
<aura:attribute name="checkRecordId" type="Boolean" default="true" />
<aura:attribute name="debug" type="Boolean" default="false" />
<aura:handler name="SubscribeStreamingChannelEvent" event="c:SubscribeStreamingChannelEvent" action="{!c.handleSubscribeEvent}"/>
<aura:handler name="destroy" value="{!this}" action="{!c.unsubscribe}"/>
<c:StreamingChannelSubscriber channel="{!v.channel}" debug="{!v.debug}" />
</aura:component>
({
handleSubscribeEvent : function(component, event, helper) {
const debug = component.get("v.debug");
const message = event.getParam('recordData');
const eventType = message.payload.ChangeEventHeader.changeType;
const entityName = message.payload.ChangeEventHeader.entityName;
const userId = message.payload.ChangeEventHeader.commitUser.substring(0, 15); //15 digit id of transaction commit user
const signedInUser= $A.get("$SObjectType.CurrentUser.Id").substring(0, 15); //15 digit id of logged in user
const checkRecordId = component.get("v.checkRecordId");
/**
* Conditions:
* - Change Type should not be create
* - Record Id must present in modified recordIds
* - User who modified the record should not be logged in user
* */
if(!(eventType === "CREATE")){
//Condition 1 - Change type is not "created"
Array.from(message.payload.ChangeEventHeader.recordIds).forEach( recordId => {
if(debug && checkRecordId) console.log("Record Id on page = " + component.get("v.recordId") + " - Record Id in event = " + recordId);
if(!checkRecordId || (checkRecordId && recordId === component.get("v.recordId"))){
//Condition 2 - Record Id match found &&
//Condition 3 - commit user is not logged in user
//Display console log with changed values
if(debug) console.log(`${eventType} event captured on ${entityName} by user id ${userId}`);
if(debug) console.log("Values changed are:");
}
});
}
}
})
-
- Mathieu Perrin 13
- March 19, 2019
- Like
- 0
Method does not exist or incorrect signature: Test.testSandboxPostCopyScript(SandboxPostRefresh, Id, Id, String)
Hello,
I created an Apex class to be launched after a sandbox refresh.
I am trying to implement the test class corresponding but I got the following error :
Here is my test class :
And my post refresh class :
I created an Apex class to be launched after a sandbox refresh.
I am trying to implement the test class corresponding but I got the following error :
Method does not exist or incorrect signature: Test.testSandboxPostCopyScript(SandboxPostRefresh, Id, Id, String)Someone already had this error ? My class is set on version 38.
Here is my test class :
@isTest
private class SandboxPostRefreshTest {
@isTest static void testSandboxPostRefresh() {
Test.startTest();
SandboxPostRefresh ClassInstance = new SandboxPostRefresh();
System.Test.testSandboxPostCopyScript(ClassInstance, UserInfo.getOrganizationId(), UserInfo.getOrganizationId(), 'sandboxName');
Test.stoptest();
}
}
And my post refresh class :
global class SandboxPostRefresh {
global void runApexClass(SandboxContext context) {
NexthinkProvider np = NexthinkProvider.getInstance();
String[] opportunityRecordTypes = new String[]{'New Customer','NBS','Services','Renewal','Upsell'};
Schema.DescribeSObjectResult oSchema = Schema.SObjectType.Opportunity;
Map<String,Schema.RecordTypeInfo> rtMapByName = oSchema.getRecordTypeInfosByName();
// Create accounts
List<Map<String, Object>> accountsProperties = new List<Map<String, Object>>();
for (Integer i = 1; i <= 13; i++) {
String industry = Randomizer.getRandomPickListValue(Account.sObjectType, null, 'Industry', false);
Account a = new Account();
Randomizer.getRandomPickListValue(null, a, 'Industry', false);
Map<String, Object> accountProperties = new Map<String, Object>();
if(i == 13) {
accountProperties.put('Name', 'Direct');
}
else {
accountProperties.put('Name', Randomizer.getRandomCompanyName());
}
accountProperties.put('Industry', Randomizer.getRandomPickListValue(Account.sObjectType, null, 'Industry', false));
if(i <= 3) {
accountProperties.put('Type', 'Potential Customer');
}
else if(i > 3 && i <= 6) {
accountProperties.put('Type', 'Customer');
}
else if(i > 6 && i <= 9) {
accountProperties.put('Type', 'Potential Partner');
accountProperties.put('Industry', 'Technology');
}
else if(i > 9 && i <= 13) {
accountProperties.put('Type', 'Partner');
accountProperties.put('Industry', 'Technology');
}
accountProperties.put('CurrencyIsoCode', Randomizer.getRandomCurrency());
accountProperties.put('Country__c', Randomizer.getRandomCountry());
accountsProperties.add(accountProperties);
}
List<Account> accounts = np.createAccounts(accountsProperties);
List<Account> partners = new List<Account>();
for(Account a : accounts) {
if(a.Type == 'Potential Partner' || a.Type == 'Partner') {
partners.add(a);
}
}
List<Map<String, Object>> contactsProperties = new List<Map<String, Object>>();
List<Map<String, Object>> opportunitesProperties = new List<Map<String, Object>>();
for(Account a : accounts) {
// Create contacts
Map<String, Object> contactProperties = new Map<String, Object>();
contactProperties.put('FirstName', Randomizer.getRandomFirstname());
contactProperties.put('LastName', Randomizer.getRandomLastname());
contactProperties.put('Phone', Randomizer.getRandomPhoneNumber());
contactProperties.put('AccountId', a.Id);
String firstname = (String) contactProperties.get('FirstName');
String lastname = (String) contactProperties.get('LastName');
contactProperties.put('Email', firstname.toLowerCase() + '.' + lastname.toLowerCase() + '@' + a.Name.toLowerCase() + '.com');
contactProperties.put('Country__c', a.Country__c);
contactProperties.put('LeadSource', Randomizer.getRandomPickListValue(Contact.sObjectType, null, 'LeadSource', false));
contactsProperties.add(contactProperties);
if(a.Name != 'Direct' && a.Type != 'Partner' && a.Type != 'Potential Partner') {
for (Integer i = 1; i <= 3; i++) {
// Create opportunities
Map<String, Object> opportunityProperties = new Map<String, Object>();
String partnerName;
if(Randomizer.getRandomBoolean()) {
Account partner = partners.get(Randomizer.getRandomNumber(6));
partnerName = partner.Name;
opportunityProperties.put('Partner_Lookup__c', partner.Id);
}
else {
partnerName = 'Direct';
}
Schema.RecordTypeInfo rt = rtMapByName.get(Randomizer.getRandomString(opportunityRecordTypes));
opportunityProperties.put('RecordTypeId', rt.getRecordTypeId());
opportunityProperties.put('Name', a.Name + '_' + partnerName + '_' + rt.getName());
opportunityProperties.put('AccountId', a.Id);
opportunityProperties.put('CurrencyIsoCode', a.CurrencyIsoCode);
opportunityProperties.put('CloseDate', Date.today().addDays(Randomizer.getRandomNumber(90)));
opportunityProperties.put('StageName', 'Unqualified');
opportunityProperties.put('Probability', 11);
opportunityProperties.put('LeadSource', Randomizer.getRandomPickListValue(Opportunity.sObjectType, null, 'LeadSource', false));
opportunityProperties.put('Contract_Start_Date__c', ((Date) opportunityProperties.get('CloseDate')).addDays(1));
String contractCommitment = Randomizer.getRandomPickListValue(Opportunity.sObjectType, null, 'Contract_Commitment__c', false);
opportunityProperties.put('Contract_Commitment__c', contractCommitment);
if(contractCommitment == '<1 Year') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(90));
}
else if(contractCommitment == '1 Year') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(Randomizer.getRandomNumber(365)));
}
else if(contractCommitment == '2 Years') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*2));
}
else if(contractCommitment == '3 Years') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*3));
}
else if(contractCommitment == '4 Years') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*4));
}
else if(contractCommitment == '5 Years') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*5));
}
else {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(500));
}
opportunitesProperties.add(opportunityProperties);
}
}
}
List<Contact> contacts = np.createContacts(contactsProperties);
List<Opportunity> opportunities = np.createOpportunities(opportunitesProperties);
// Get all products
Map<String, Product2> productsMap = new Map<String, Product2>();
for(Product2 product : [SELECT Id, Name FROM Product2]) {
productsMap.put(product.Name, product);
}
// Create OpportunityLineItem
Map<Opportunity,List<Object>> olisMap = new Map<Opportunity,List<Object>>();
for(Opportunity o : opportunities) {
List<Object> tempList = new List<Object>();
List<Product2> opportunityProductList = new List<Product2>();
Map<String, Object> oliProperties = new Map<String, Object>();
oliProperties.put('Description', 'SKU');
if(o.RecordTypeId == rtMapByName.get('New Customer').getRecordTypeId() || o.RecordTypeId == rtMapByName.get('Upsell').getRecordTypeId()) {
oliProperties.put('Quantity', 100);
opportunityProductList.add(productsMap.get('Endpoint Collector - License'));
if(Randomizer.getRandomBoolean()) {
opportunityProductList.add(productsMap.get('Endpoint Collector - Maintenance 1yr'));
}
else {
opportunityProductList.add(productsMap.get('Endpoint Collector - Subscription 1yr'));
}
if(Randomizer.getRandomBoolean()) {
opportunityProductList.add(productsMap.get('Time & Material billed upon completion - per day'));
}
}
if(o.RecordTypeId == rtMapByName.get('NBS').getRecordTypeId()) {
oliProperties.put('Quantity', 5);
opportunityProductList.add(productsMap.get('Baseline Service 1-Engine'));
}
if(o.RecordTypeId == rtMapByName.get('Renewal').getRecordTypeId()) {
oliProperties.put('Quantity', 1000);
if(Randomizer.getRandomBoolean()) {
opportunityProductList.add(productsMap.get('Renewal Endpoint Collector - Subscription 1yr'));
}
else {
opportunityProductList.add(productsMap.get('Renewal Endpoint Collector - Maintenance 1yr'));
}
}
if(o.RecordTypeId == rtMapByName.get('Services').getRecordTypeId()) {
oliProperties.put('Quantity', 10);
Integer random = Randomizer.getRandomNumber(3);
if(random == 1) {
opportunityProductList.add(productsMap.get('Time & Material billed upon completion - per day'));
}
else if(random == 2) {
opportunityProductList.add(productsMap.get('Service Fee Billed in Advance'));
}
else if(random == 3) {
opportunityProductList.add(productsMap.get('Fixed fee billed upon milestone completion'));
}
}
tempList.add(opportunityProductList);
tempList.add(oliProperties);
olisMap.put(o, tempList);
}
np.addProducts(olisMap);
}
}
-
- Mathieu Perrin 13
- October 31, 2016
- Like
- 0
Method does not exist or incorrect signature: Test.testSandboxPostCopyScript(SandboxPostRefresh, Id, Id, String)
Hello,
I created an Apex class to be launched after a sandbox refresh.
I am trying to implement the test class corresponding but I got the following error :
Here is my test class :
And my post refresh class :
I created an Apex class to be launched after a sandbox refresh.
I am trying to implement the test class corresponding but I got the following error :
Method does not exist or incorrect signature: Test.testSandboxPostCopyScript(SandboxPostRefresh, Id, Id, String)Someone already had this error ? My class is set on version 38.
Here is my test class :
@isTest
private class SandboxPostRefreshTest {
@isTest static void testSandboxPostRefresh() {
Test.startTest();
SandboxPostRefresh ClassInstance = new SandboxPostRefresh();
System.Test.testSandboxPostCopyScript(ClassInstance, UserInfo.getOrganizationId(), UserInfo.getOrganizationId(), 'sandboxName');
Test.stoptest();
}
}
And my post refresh class :
global class SandboxPostRefresh {
global void runApexClass(SandboxContext context) {
NexthinkProvider np = NexthinkProvider.getInstance();
String[] opportunityRecordTypes = new String[]{'New Customer','NBS','Services','Renewal','Upsell'};
Schema.DescribeSObjectResult oSchema = Schema.SObjectType.Opportunity;
Map<String,Schema.RecordTypeInfo> rtMapByName = oSchema.getRecordTypeInfosByName();
// Create accounts
List<Map<String, Object>> accountsProperties = new List<Map<String, Object>>();
for (Integer i = 1; i <= 13; i++) {
String industry = Randomizer.getRandomPickListValue(Account.sObjectType, null, 'Industry', false);
Account a = new Account();
Randomizer.getRandomPickListValue(null, a, 'Industry', false);
Map<String, Object> accountProperties = new Map<String, Object>();
if(i == 13) {
accountProperties.put('Name', 'Direct');
}
else {
accountProperties.put('Name', Randomizer.getRandomCompanyName());
}
accountProperties.put('Industry', Randomizer.getRandomPickListValue(Account.sObjectType, null, 'Industry', false));
if(i <= 3) {
accountProperties.put('Type', 'Potential Customer');
}
else if(i > 3 && i <= 6) {
accountProperties.put('Type', 'Customer');
}
else if(i > 6 && i <= 9) {
accountProperties.put('Type', 'Potential Partner');
accountProperties.put('Industry', 'Technology');
}
else if(i > 9 && i <= 13) {
accountProperties.put('Type', 'Partner');
accountProperties.put('Industry', 'Technology');
}
accountProperties.put('CurrencyIsoCode', Randomizer.getRandomCurrency());
accountProperties.put('Country__c', Randomizer.getRandomCountry());
accountsProperties.add(accountProperties);
}
List<Account> accounts = np.createAccounts(accountsProperties);
List<Account> partners = new List<Account>();
for(Account a : accounts) {
if(a.Type == 'Potential Partner' || a.Type == 'Partner') {
partners.add(a);
}
}
List<Map<String, Object>> contactsProperties = new List<Map<String, Object>>();
List<Map<String, Object>> opportunitesProperties = new List<Map<String, Object>>();
for(Account a : accounts) {
// Create contacts
Map<String, Object> contactProperties = new Map<String, Object>();
contactProperties.put('FirstName', Randomizer.getRandomFirstname());
contactProperties.put('LastName', Randomizer.getRandomLastname());
contactProperties.put('Phone', Randomizer.getRandomPhoneNumber());
contactProperties.put('AccountId', a.Id);
String firstname = (String) contactProperties.get('FirstName');
String lastname = (String) contactProperties.get('LastName');
contactProperties.put('Email', firstname.toLowerCase() + '.' + lastname.toLowerCase() + '@' + a.Name.toLowerCase() + '.com');
contactProperties.put('Country__c', a.Country__c);
contactProperties.put('LeadSource', Randomizer.getRandomPickListValue(Contact.sObjectType, null, 'LeadSource', false));
contactsProperties.add(contactProperties);
if(a.Name != 'Direct' && a.Type != 'Partner' && a.Type != 'Potential Partner') {
for (Integer i = 1; i <= 3; i++) {
// Create opportunities
Map<String, Object> opportunityProperties = new Map<String, Object>();
String partnerName;
if(Randomizer.getRandomBoolean()) {
Account partner = partners.get(Randomizer.getRandomNumber(6));
partnerName = partner.Name;
opportunityProperties.put('Partner_Lookup__c', partner.Id);
}
else {
partnerName = 'Direct';
}
Schema.RecordTypeInfo rt = rtMapByName.get(Randomizer.getRandomString(opportunityRecordTypes));
opportunityProperties.put('RecordTypeId', rt.getRecordTypeId());
opportunityProperties.put('Name', a.Name + '_' + partnerName + '_' + rt.getName());
opportunityProperties.put('AccountId', a.Id);
opportunityProperties.put('CurrencyIsoCode', a.CurrencyIsoCode);
opportunityProperties.put('CloseDate', Date.today().addDays(Randomizer.getRandomNumber(90)));
opportunityProperties.put('StageName', 'Unqualified');
opportunityProperties.put('Probability', 11);
opportunityProperties.put('LeadSource', Randomizer.getRandomPickListValue(Opportunity.sObjectType, null, 'LeadSource', false));
opportunityProperties.put('Contract_Start_Date__c', ((Date) opportunityProperties.get('CloseDate')).addDays(1));
String contractCommitment = Randomizer.getRandomPickListValue(Opportunity.sObjectType, null, 'Contract_Commitment__c', false);
opportunityProperties.put('Contract_Commitment__c', contractCommitment);
if(contractCommitment == '<1 Year') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(90));
}
else if(contractCommitment == '1 Year') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(Randomizer.getRandomNumber(365)));
}
else if(contractCommitment == '2 Years') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*2));
}
else if(contractCommitment == '3 Years') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*3));
}
else if(contractCommitment == '4 Years') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*4));
}
else if(contractCommitment == '5 Years') {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*5));
}
else {
opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(500));
}
opportunitesProperties.add(opportunityProperties);
}
}
}
List<Contact> contacts = np.createContacts(contactsProperties);
List<Opportunity> opportunities = np.createOpportunities(opportunitesProperties);
// Get all products
Map<String, Product2> productsMap = new Map<String, Product2>();
for(Product2 product : [SELECT Id, Name FROM Product2]) {
productsMap.put(product.Name, product);
}
// Create OpportunityLineItem
Map<Opportunity,List<Object>> olisMap = new Map<Opportunity,List<Object>>();
for(Opportunity o : opportunities) {
List<Object> tempList = new List<Object>();
List<Product2> opportunityProductList = new List<Product2>();
Map<String, Object> oliProperties = new Map<String, Object>();
oliProperties.put('Description', 'SKU');
if(o.RecordTypeId == rtMapByName.get('New Customer').getRecordTypeId() || o.RecordTypeId == rtMapByName.get('Upsell').getRecordTypeId()) {
oliProperties.put('Quantity', 100);
opportunityProductList.add(productsMap.get('Endpoint Collector - License'));
if(Randomizer.getRandomBoolean()) {
opportunityProductList.add(productsMap.get('Endpoint Collector - Maintenance 1yr'));
}
else {
opportunityProductList.add(productsMap.get('Endpoint Collector - Subscription 1yr'));
}
if(Randomizer.getRandomBoolean()) {
opportunityProductList.add(productsMap.get('Time & Material billed upon completion - per day'));
}
}
if(o.RecordTypeId == rtMapByName.get('NBS').getRecordTypeId()) {
oliProperties.put('Quantity', 5);
opportunityProductList.add(productsMap.get('Baseline Service 1-Engine'));
}
if(o.RecordTypeId == rtMapByName.get('Renewal').getRecordTypeId()) {
oliProperties.put('Quantity', 1000);
if(Randomizer.getRandomBoolean()) {
opportunityProductList.add(productsMap.get('Renewal Endpoint Collector - Subscription 1yr'));
}
else {
opportunityProductList.add(productsMap.get('Renewal Endpoint Collector - Maintenance 1yr'));
}
}
if(o.RecordTypeId == rtMapByName.get('Services').getRecordTypeId()) {
oliProperties.put('Quantity', 10);
Integer random = Randomizer.getRandomNumber(3);
if(random == 1) {
opportunityProductList.add(productsMap.get('Time & Material billed upon completion - per day'));
}
else if(random == 2) {
opportunityProductList.add(productsMap.get('Service Fee Billed in Advance'));
}
else if(random == 3) {
opportunityProductList.add(productsMap.get('Fixed fee billed upon milestone completion'));
}
}
tempList.add(opportunityProductList);
tempList.add(oliProperties);
olisMap.put(o, tempList);
}
np.addProducts(olisMap);
}
}

- Mathieu Perrin 13
- October 31, 2016
- Like
- 0