• Kruse Collins
  • NEWBIE
  • 10 Points
  • Member since 2017
  • Salesforce Admin/Jr. Dev
  • Kruse in Salesforce


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

I'm creating a custom Javascript button in SFDC classic. This button would rest on a Quote record. The ideal functionality is that this button would check and see if this particular Quote record has any child records associated with it.

  • The master-detail relationship is Quote (master) to QService__c (child).
  • The master-detail field name on the QService__c object is called Quote__c.
  • The child relationship name is QServices.

I want to try and handle any errors, so if the Quote has 1 or more QService__c records, then it would open a link in a new window (google is the test link I have so far). If the Quote doesn't have any QService__c records, then display an alert.
 

{!RequireScript("/soap/ajax/42.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")} 

var childRecords = sforce.connection.query("SELECT id, (SELECT id FROM QServices__r) FROM Quote WHERE Id = '{!Quote.Id}'"); 

if(childRecords.getArray("records").length) { 
       window.open("https://www.google.com/"); 
} else { 
       alert("There needs to be a service on this quote."); 
}​​
 

The Issue:
What's happening right now is when I DON'T have a QService__c record on the quote, still redirects to the link. So the If-statement or the Query isn't working correctly. Any suggestions on what needs to be fixed here? If it's the query or if I need to adjust my If-statement?

I'm creating a custom Javascript button in SFDC classic. This button would rest on a Quote record. The ideal functionality is that this button would check and see if this particular Quote record has any child records associated with it.

  • The master-detail relationship is Quote (master) to QService__c (child).
  • The master-detail field name on the QService__c object is called Quote__c.
  • The child relationship name is QServices.

I want to try and handle any errors, so if the Quote has 1 or more QService__c records, then it would open a link in a new window (google is the test link I have so far). If the Quote doesn't have any QService__c records, then display an alert.
 

{!RequireScript("/soap/ajax/42.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")} 

var childRecords = sforce.connection.query("SELECT id, (SELECT id FROM QServices__r) FROM Quote WHERE Id = '{!Quote.Id}'"); 

if(childRecords.getArray("records").length) { 
       window.open("https://www.google.com/"); 
} else { 
       alert("There needs to be a service on this quote."); 
}​​
 

The Issue:
What's happening right now is when I DON'T have a QService__c record on the quote, still redirects to the link. So the If-statement or the Query isn't working correctly. Any suggestions on what needs to be fixed here? If it's the query or if I need to adjust my If-statement?

Steps
1. Created a Flow to create 3 WorkOrderLineItem record based on the conditions - Record Type and Pricebook should match the expected value.

First record:
User-added image
Second Record:
User-added image
Third Record:
User-added image
The flow triggers on creating a Work Order record with the expected Record Type and PriceBook but it fails to create the third record. The field I chose in the third record is the same as that in the second record. 
I get the following error message:
Error element Testing_New (FlowRecordCreate).
This error occurred when the flow tried to create records: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id. For details, see API Exceptions.


This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: CreateWorkOrderLineItems
Type: Autolaunched Flow
Version: 30
Status: Active
Flow Interview Details
Interview Label: CreateWorkOrderLineItems 14/02/2018 3:27 PM
Current User: Johnson Titus (005w0000006It4x)
Start time: 14/02/2018 3:27 PM
Duration: 0 seconds
How the Interview Started
Johnson Titus (005w0000006It4x) started the flow interview.
Some of this flow's variables were set when the interview started.
varWorkOrderId = 0WO2X000000019JWAQ
varAccountId = 00120000006GOmQAAW
varWorkOrderRecordType = 012w0000000kdo3AAA
RECORD QUERY: WorkOrderLookup
Find one WorkOrder record where:
Id Equals {!varWorkOrderId} (0WO2X000000019JWAQ)
Result
Successfully found record.
{!varAccountId} = 00120000006GOmQAAW
{!varPriceBook} = 01sw0000001yRHPAA2
{!varWorkOrderRecordType} = 012w0000000kdo3AAA
DECISION: RecordType
Executed this outcome: General_Upgrade
Outcome conditions: and
1. {!varWorkOrderRecordType} (012w0000000kdo3AAA) Equals 012w0000000kdo3AAA
Logic: All conditions must be true (AND)
DECISION: ClientOrSupport_1_1
Executed this outcome: Support_1_1
Outcome conditions: and
1. {!varPriceBook} (01sw0000001yRHPAA2) Equals 01sw0000001yRHPAA2
Logic: All conditions must be true (AND)
RECORD CREATE: BRMsClientSignOff
Create one WorkOrderLineItem record where:
PricebookEntryId = 01uw000000zlKySAAU
RecordTypeId = 012w0000000kdmHAAQ
StartDate = {!Flow.CurrentDateTime} (14/02/2018 3:27 PM)
Subject = BRM's Client Sign Off
Type__c = BRM's Client Sign Off
WorkOrderId = {!varWorkOrderId} (0WO2X000000019JWAQ)
Result
A record is ready to be created when the next Screen or Wait element is executed or when the interview finishes.
RECORD CREATE: UpgradeAttach1xto_AttachBI
Create one WorkOrderLineItem record where:
PricebookEntryId = 01uw000000zlKyQAAU
RecordTypeId = 012w0000000kdj8AAA
StartDate = {!Flow.CurrentDateTime} (14/02/2018 3:27 PM)
Subject = Upgrade Attaché 1x to Attaché BI
Type__c = Install
WorkOrderId = {!varWorkOrderId} (0WO2X000000019JWAQ)
Result
A record is ready to be created when the next Screen or Wait element is executed or when the interview finishes.
RECORD CREATE: Testing_New
Create one WorkOrderLineItem record where:
PricebookEntryId = 01uw000000zlKyQAAU
Result
Failed to create record.

Error Occurred: This error occurred when the flow tried to create records: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id. For details, see API Exceptions.


Salesforce Error ID: 106773568-45175 (164668177)