• James Billings
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 6
    Replies

Hi all,

I'm just having a tinker around with remoting to see if it can help out with an issue we're having. 

I've set up a very simple page/controller with a "hello world" method that I'm just dumping out to console to see if the remote calls themselves work (the source of the call is actually via a Zuora javascript plugin which may or may not be relevant)...

Anyway, the expected "hello world" output is not seen in the console, instead I get this warning:

Visualforce Remoting: Context incomplete - authorization not provided

A bit of googling suggests this might be down to enhanced security in Winter 22, but I can't find any information on how to resolve it...

What authorization is missing? How do I add it? I read over the article at https://help.salesforce.com/s/articleView?id=release-notes.rn_vf_js_remoting_security_ru.htm&type=5&release=232&language=en_US but that basically says "find your problems and then fix them" :)

Code samples below if useful...

MyCpqSelectProduct page:

<apex:page sidebar="false" tabStyle="zqu__Quote__c" standardController="zqu__Quote__c" extensions="MyCpqSelectProductController">
  <script>
    var asyncHello = function(callback) {
      Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.MyCpqSelectProductController.helloWorld}',
        function(result, event) {
          callback(result);
        }
      );
    };
  </script>
  <apex:form >
    <zqu:CpqSelectProduct options="{!theOptions}"/>
  </apex:form>
</apex:page>

MyCpqSelectProductController:

global with sharing class MyCpqSelectProductController
{
    global zqu.SelectProductComponentOptions theOptions { get; set; }

    global MyCpqSelectProductController(ApexPages.StandardController controller)
    {
        theOptions = new zqu.SelectProductComponentOptions();
        theOptions.mode = zqu.SelectProductComponentOptions.MODE_EDIT;
        theOptions.quoteId = controller.getId();
    }

    @RemoteAction
    global static String helloWorld()
    {
        return 'Hello World';
    }
}

Zuora Product Selector JS where the above is called:

var ProductSelectorPlugin = function(){

    return {
        postRecalculateZCharge : function(previousZCharge,
                                          currentZCharge,
                                          chargeGroup,
                                          quote,
                                          allChargeGroups) {

            asyncHello(function(result) {
                console.log('Received info:');
                console.log(result);
            });
....... (remaining existing functionality below)
Zuora docs where the above "starter" was taken from: https://knowledgecenter.zuora.com/CPQ/I_Development_Resources/C_Component_Library/E_Product_Selector_JavaScript_Plugin/Remote_Calls_with_JavaScript_Plugin 

 

 

I'm writing some tests for a class which can trigger a couple of different queueables. 

In the tests, we have a mock implementaion of ISystemOperation which increments a number when a call to enqueue is made... 

I now want to only increment the counter when the expected queueable class is used, but I cannot find out a way of getting this... Example (pseudo)code, the line marked with **** is the one I'm wondering how to implement:
 

private class CapturingSystemOperation implements ISystemOperation
    {
        public Integer CallCount = 0;
        public String expectedClassName;

        public String enqueueJob(Queueable queueableClass)
        {
********if (queueableClass.class.Name == expectedClassName)
            {
                CallCount++;
            }

            return Utils.getFakeId(AsyncApexJob.SObjectType);
        }
    }
 

Any ideas?  

I have a Queueable class which uses a 3rd party package to do some callouts to another system, and I'm trying to write some tests for my class. 

I've created my own fake instance of the API, where the methods simply set properties... Simplified example:

public class FakeApiTest implements IApi
{
     public String passedQueryString;

     public List<Object> QueryObjects(String queryString)
     {
            passedQueryString = queryString;
            return new List<Object>{};
     }
}


In my test, I pass in an instance of the above to my Queueable, but if I try and retrieve the property values after my Queueable executes (wrapped within StartTest/StopTest), it's always null.

Any ideas how I can get my values back out? 

I have a method in a class which is sending an email out. It works fine, but I want to add a test for it. 

I've created my test, and used the following to check if the email was queued: 

Integer invocations = Limits.getEmailInvocations();
        System.assertEquals(1, invocations);
 

However it always fails, with invocations being 0. I added debug statements to my email-sending method, and these suggest it's "working" from the test (i.e. Messaging.sendEmail returns success). 

One possible cause is that the method that calls the email sending method is a @Future(callout=true) - would this cause the emailinvocations to not get seen in the test? 


 

I've added a date field to an object, which is populated with a simple formula of "NOW()". 
The problem is that this inserts the date as UTC. What I actually need to happen is that the value is inserted using the date/time of the user submitting the item for approval.
For example, it's currently 7am on the 29th June here in the UK. If I log in via a computer in Pacific time where the local time is still the day before (28th) and submit approval, the date is still populated as the 29th. 
How can I get this to be filled in with the date value of the user requesting approval?
I'm trying to see if I can deploy some ApprovalProcess instances (using the ant tool for now). I've retrieved the processes themselves by adding the relevant bit to package.xml. But I'm not sure where the FieldUpdate action lives. The Approval Process file contains the name of it:
 
<approvalStep>
        <allowDelegate>false</allowDelegate>
        <approvalActions>
            <action>
                <name>UpdateApprovalStatus</name>
                <type>FieldUpdate</type>
            </action>
        </approvalActions>
......

But the actual object/field isn't listed anywhere. Can I retrieve/deploy that as well? If so? where does it live and what do I need to add to package.xml to pick it up?
Does anyone know if I can create a public share link for a file via code? 
I can do it via the Files UI, and I can then find this in the ContentDistribution object, but it still requires the user to have generated the link to begin with. 
Ideally I want to do this in code as part of a trigger. Any suggestions?

I'm writing some tests for a class which can trigger a couple of different queueables. 

In the tests, we have a mock implementaion of ISystemOperation which increments a number when a call to enqueue is made... 

I now want to only increment the counter when the expected queueable class is used, but I cannot find out a way of getting this... Example (pseudo)code, the line marked with **** is the one I'm wondering how to implement:
 

private class CapturingSystemOperation implements ISystemOperation
    {
        public Integer CallCount = 0;
        public String expectedClassName;

        public String enqueueJob(Queueable queueableClass)
        {
********if (queueableClass.class.Name == expectedClassName)
            {
                CallCount++;
            }

            return Utils.getFakeId(AsyncApexJob.SObjectType);
        }
    }
 

Any ideas?  

I have a method in a class which is sending an email out. It works fine, but I want to add a test for it. 

I've created my test, and used the following to check if the email was queued: 

Integer invocations = Limits.getEmailInvocations();
        System.assertEquals(1, invocations);
 

However it always fails, with invocations being 0. I added debug statements to my email-sending method, and these suggest it's "working" from the test (i.e. Messaging.sendEmail returns success). 

One possible cause is that the method that calls the email sending method is a @Future(callout=true) - would this cause the emailinvocations to not get seen in the test? 


 

I've added a date field to an object, which is populated with a simple formula of "NOW()". 
The problem is that this inserts the date as UTC. What I actually need to happen is that the value is inserted using the date/time of the user submitting the item for approval.
For example, it's currently 7am on the 29th June here in the UK. If I log in via a computer in Pacific time where the local time is still the day before (28th) and submit approval, the date is still populated as the 29th. 
How can I get this to be filled in with the date value of the user requesting approval?
Does anyone know if I can create a public share link for a file via code? 
I can do it via the Files UI, and I can then find this in the ContentDistribution object, but it still requires the user to have generated the link to begin with. 
Ideally I want to do this in code as part of a trigger. Any suggestions?