InvocableMethod Through anonymous APEX












3















I have an invocablemethod that runs from a process builder that got broken for a few months I had a mapping issue and some fields didn't populate or create for various reasons. In the process builder you only need to pass the Opportunity Id and a string variable and it does the work.



I want to fix my error and pass in Opportunity Ids directly to the method however, I can't figure out how to populate the data to do it.



Example:



@InvocableMethod(label='Perform Mapping' description='Performs a ConvertAnything mapping given a list of records.')
global static void generateAndInsertAllRecords(List<ContextRecord> contextRecords)
{
// do stuff
}


ContextRecord is defined here:



global class SL_Mapping_Handler extends SL_Mapping_Handler_Helper {

// used for determining which records to perform the mapping from
global class ContextRecord {
@InvocableVariable(label='Id' required=true)
global Id Id;
@InvocableVariable(label='Custom Mapping Identifier')
global String customMappingIdentifier;
}


I'm in anon apex trying to do something like this:



SL_Mapping_Handler.ContextRecord cr = new SL_MApping_Handler.ContextRecord();
cr.Id = '006A000000YN0gd';
cr.customMappingIdentifier = 'Opp Auto Renewal';

List<ContextRecord> l = new List<ContextRecord>();
l.add(cr);
SL_Mapping_Handler.generateAndInsertAllRecords(l);


But I get an error:




Line: 3, Column: 1 Invalid type: ContextRecord




Is this possible to do? Is it just a syntax error?










share|improve this question





























    3















    I have an invocablemethod that runs from a process builder that got broken for a few months I had a mapping issue and some fields didn't populate or create for various reasons. In the process builder you only need to pass the Opportunity Id and a string variable and it does the work.



    I want to fix my error and pass in Opportunity Ids directly to the method however, I can't figure out how to populate the data to do it.



    Example:



    @InvocableMethod(label='Perform Mapping' description='Performs a ConvertAnything mapping given a list of records.')
    global static void generateAndInsertAllRecords(List<ContextRecord> contextRecords)
    {
    // do stuff
    }


    ContextRecord is defined here:



    global class SL_Mapping_Handler extends SL_Mapping_Handler_Helper {

    // used for determining which records to perform the mapping from
    global class ContextRecord {
    @InvocableVariable(label='Id' required=true)
    global Id Id;
    @InvocableVariable(label='Custom Mapping Identifier')
    global String customMappingIdentifier;
    }


    I'm in anon apex trying to do something like this:



    SL_Mapping_Handler.ContextRecord cr = new SL_MApping_Handler.ContextRecord();
    cr.Id = '006A000000YN0gd';
    cr.customMappingIdentifier = 'Opp Auto Renewal';

    List<ContextRecord> l = new List<ContextRecord>();
    l.add(cr);
    SL_Mapping_Handler.generateAndInsertAllRecords(l);


    But I get an error:




    Line: 3, Column: 1 Invalid type: ContextRecord




    Is this possible to do? Is it just a syntax error?










    share|improve this question



























      3












      3








      3








      I have an invocablemethod that runs from a process builder that got broken for a few months I had a mapping issue and some fields didn't populate or create for various reasons. In the process builder you only need to pass the Opportunity Id and a string variable and it does the work.



      I want to fix my error and pass in Opportunity Ids directly to the method however, I can't figure out how to populate the data to do it.



      Example:



      @InvocableMethod(label='Perform Mapping' description='Performs a ConvertAnything mapping given a list of records.')
      global static void generateAndInsertAllRecords(List<ContextRecord> contextRecords)
      {
      // do stuff
      }


      ContextRecord is defined here:



      global class SL_Mapping_Handler extends SL_Mapping_Handler_Helper {

      // used for determining which records to perform the mapping from
      global class ContextRecord {
      @InvocableVariable(label='Id' required=true)
      global Id Id;
      @InvocableVariable(label='Custom Mapping Identifier')
      global String customMappingIdentifier;
      }


      I'm in anon apex trying to do something like this:



      SL_Mapping_Handler.ContextRecord cr = new SL_MApping_Handler.ContextRecord();
      cr.Id = '006A000000YN0gd';
      cr.customMappingIdentifier = 'Opp Auto Renewal';

      List<ContextRecord> l = new List<ContextRecord>();
      l.add(cr);
      SL_Mapping_Handler.generateAndInsertAllRecords(l);


      But I get an error:




      Line: 3, Column: 1 Invalid type: ContextRecord




      Is this possible to do? Is it just a syntax error?










      share|improve this question
















      I have an invocablemethod that runs from a process builder that got broken for a few months I had a mapping issue and some fields didn't populate or create for various reasons. In the process builder you only need to pass the Opportunity Id and a string variable and it does the work.



      I want to fix my error and pass in Opportunity Ids directly to the method however, I can't figure out how to populate the data to do it.



      Example:



      @InvocableMethod(label='Perform Mapping' description='Performs a ConvertAnything mapping given a list of records.')
      global static void generateAndInsertAllRecords(List<ContextRecord> contextRecords)
      {
      // do stuff
      }


      ContextRecord is defined here:



      global class SL_Mapping_Handler extends SL_Mapping_Handler_Helper {

      // used for determining which records to perform the mapping from
      global class ContextRecord {
      @InvocableVariable(label='Id' required=true)
      global Id Id;
      @InvocableVariable(label='Custom Mapping Identifier')
      global String customMappingIdentifier;
      }


      I'm in anon apex trying to do something like this:



      SL_Mapping_Handler.ContextRecord cr = new SL_MApping_Handler.ContextRecord();
      cr.Id = '006A000000YN0gd';
      cr.customMappingIdentifier = 'Opp Auto Renewal';

      List<ContextRecord> l = new List<ContextRecord>();
      l.add(cr);
      SL_Mapping_Handler.generateAndInsertAllRecords(l);


      But I get an error:




      Line: 3, Column: 1 Invalid type: ContextRecord




      Is this possible to do? Is it just a syntax error?







      apex invocable-method






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 11 hours ago









      Adrian Larson

      108k19115243




      108k19115243










      asked 11 hours ago









      Dan WoodingDan Wooding

      1,9671137




      1,9671137






















          1 Answer
          1






          active

          oldest

          votes


















          4














          You will need to declare the list in your snippet as:



          List<SL_Mapping_Handler.ContextRecord> l = new List<SL_Mapping_Handler.ContextRecord>();


          Replaces:



          List<ContextRecord> l = new List<ContextRecord>();





          share|improve this answer





















          • 1





            Beat me to it. The issue was that OP was trying to reference an inner class outside of its containing class. Unless you're inside SL_Mapping_Handler, you need to prepend the name of the outer class to be able to use the inner class.

            – Derek F
            11 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "459"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f250225%2finvocablemethod-through-anonymous-apex%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          You will need to declare the list in your snippet as:



          List<SL_Mapping_Handler.ContextRecord> l = new List<SL_Mapping_Handler.ContextRecord>();


          Replaces:



          List<ContextRecord> l = new List<ContextRecord>();





          share|improve this answer





















          • 1





            Beat me to it. The issue was that OP was trying to reference an inner class outside of its containing class. Unless you're inside SL_Mapping_Handler, you need to prepend the name of the outer class to be able to use the inner class.

            – Derek F
            11 hours ago
















          4














          You will need to declare the list in your snippet as:



          List<SL_Mapping_Handler.ContextRecord> l = new List<SL_Mapping_Handler.ContextRecord>();


          Replaces:



          List<ContextRecord> l = new List<ContextRecord>();





          share|improve this answer





















          • 1





            Beat me to it. The issue was that OP was trying to reference an inner class outside of its containing class. Unless you're inside SL_Mapping_Handler, you need to prepend the name of the outer class to be able to use the inner class.

            – Derek F
            11 hours ago














          4












          4








          4







          You will need to declare the list in your snippet as:



          List<SL_Mapping_Handler.ContextRecord> l = new List<SL_Mapping_Handler.ContextRecord>();


          Replaces:



          List<ContextRecord> l = new List<ContextRecord>();





          share|improve this answer















          You will need to declare the list in your snippet as:



          List<SL_Mapping_Handler.ContextRecord> l = new List<SL_Mapping_Handler.ContextRecord>();


          Replaces:



          List<ContextRecord> l = new List<ContextRecord>();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 11 hours ago









          Daniel Ballinger

          73k15149394




          73k15149394










          answered 11 hours ago









          Jayant DasJayant Das

          14.3k2824




          14.3k2824








          • 1





            Beat me to it. The issue was that OP was trying to reference an inner class outside of its containing class. Unless you're inside SL_Mapping_Handler, you need to prepend the name of the outer class to be able to use the inner class.

            – Derek F
            11 hours ago














          • 1





            Beat me to it. The issue was that OP was trying to reference an inner class outside of its containing class. Unless you're inside SL_Mapping_Handler, you need to prepend the name of the outer class to be able to use the inner class.

            – Derek F
            11 hours ago








          1




          1





          Beat me to it. The issue was that OP was trying to reference an inner class outside of its containing class. Unless you're inside SL_Mapping_Handler, you need to prepend the name of the outer class to be able to use the inner class.

          – Derek F
          11 hours ago





          Beat me to it. The issue was that OP was trying to reference an inner class outside of its containing class. Unless you're inside SL_Mapping_Handler, you need to prepend the name of the outer class to be able to use the inner class.

          – Derek F
          11 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f250225%2finvocablemethod-through-anonymous-apex%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]