Accommodate the length of a string value to prevent the STRING_TOO_LONG issue

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
4
down vote

favorite
2












I received an exception while trying to insert an order item. It appears to be that the description field allows only 255 characters; sometimes my descriptions goes beyond 255.



I will shorten the length of the description before inserting the entry. See the code as follows:



Order ord = new Order(.....);

String description = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, ';

if(description.length() > 255)
description = description.abbreviate(255);


ord.Description = description;

insert ord;


I am wondering whether there is an easier way to accomplish this by using the Salesforce built-in features. Meaning without writing code.










share|improve this question





























    up vote
    4
    down vote

    favorite
    2












    I received an exception while trying to insert an order item. It appears to be that the description field allows only 255 characters; sometimes my descriptions goes beyond 255.



    I will shorten the length of the description before inserting the entry. See the code as follows:



    Order ord = new Order(.....);

    String description = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, ';

    if(description.length() > 255)
    description = description.abbreviate(255);


    ord.Description = description;

    insert ord;


    I am wondering whether there is an easier way to accomplish this by using the Salesforce built-in features. Meaning without writing code.










    share|improve this question

























      up vote
      4
      down vote

      favorite
      2









      up vote
      4
      down vote

      favorite
      2






      2





      I received an exception while trying to insert an order item. It appears to be that the description field allows only 255 characters; sometimes my descriptions goes beyond 255.



      I will shorten the length of the description before inserting the entry. See the code as follows:



      Order ord = new Order(.....);

      String description = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, ';

      if(description.length() > 255)
      description = description.abbreviate(255);


      ord.Description = description;

      insert ord;


      I am wondering whether there is an easier way to accomplish this by using the Salesforce built-in features. Meaning without writing code.










      share|improve this question















      I received an exception while trying to insert an order item. It appears to be that the description field allows only 255 characters; sometimes my descriptions goes beyond 255.



      I will shorten the length of the description before inserting the entry. See the code as follows:



      Order ord = new Order(.....);

      String description = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, ';

      if(description.length() > 255)
      description = description.abbreviate(255);


      ord.Description = description;

      insert ord;


      I am wondering whether there is an easier way to accomplish this by using the Salesforce built-in features. Meaning without writing code.







      apex fields string






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 18 at 1:09









      Peter Mortensen

      23117




      23117










      asked Aug 17 at 9:28









      Cuban coffee

      538213




      538213




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          You can use the allowFieldTruncation header in the DMLOptions Class.



          Order record = new Order(...);
          Database.DMLOptions opt = new Database.DMLOptions();
          opt.allowFieldTruncation = true;
          Database.insert(record, opt);


          If you're dong this from elsewhere (e.g. the API), there are similar headers you can use for allowFieldTruncation to prevent errors from appearing when field values are too long, without additional code.






          share|improve this answer




















          • I see. Is there a way to specify a concrete field? I am assuming that by using the DMLOption approach will truncate all the fields if required.
            – Cuban coffee
            Aug 17 at 9:56







          • 1




            @Cubancoffee Yes, it will allow all fields to truncate. If you need more specific behavior, you would have to do it one-off.
            – sfdcfox
            Aug 17 at 9:57










          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f229209%2faccommodate-the-length-of-a-string-value-to-prevent-the-string-too-long-issue%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote



          accepted










          You can use the allowFieldTruncation header in the DMLOptions Class.



          Order record = new Order(...);
          Database.DMLOptions opt = new Database.DMLOptions();
          opt.allowFieldTruncation = true;
          Database.insert(record, opt);


          If you're dong this from elsewhere (e.g. the API), there are similar headers you can use for allowFieldTruncation to prevent errors from appearing when field values are too long, without additional code.






          share|improve this answer




















          • I see. Is there a way to specify a concrete field? I am assuming that by using the DMLOption approach will truncate all the fields if required.
            – Cuban coffee
            Aug 17 at 9:56







          • 1




            @Cubancoffee Yes, it will allow all fields to truncate. If you need more specific behavior, you would have to do it one-off.
            – sfdcfox
            Aug 17 at 9:57














          up vote
          6
          down vote



          accepted










          You can use the allowFieldTruncation header in the DMLOptions Class.



          Order record = new Order(...);
          Database.DMLOptions opt = new Database.DMLOptions();
          opt.allowFieldTruncation = true;
          Database.insert(record, opt);


          If you're dong this from elsewhere (e.g. the API), there are similar headers you can use for allowFieldTruncation to prevent errors from appearing when field values are too long, without additional code.






          share|improve this answer




















          • I see. Is there a way to specify a concrete field? I am assuming that by using the DMLOption approach will truncate all the fields if required.
            – Cuban coffee
            Aug 17 at 9:56







          • 1




            @Cubancoffee Yes, it will allow all fields to truncate. If you need more specific behavior, you would have to do it one-off.
            – sfdcfox
            Aug 17 at 9:57












          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          You can use the allowFieldTruncation header in the DMLOptions Class.



          Order record = new Order(...);
          Database.DMLOptions opt = new Database.DMLOptions();
          opt.allowFieldTruncation = true;
          Database.insert(record, opt);


          If you're dong this from elsewhere (e.g. the API), there are similar headers you can use for allowFieldTruncation to prevent errors from appearing when field values are too long, without additional code.






          share|improve this answer












          You can use the allowFieldTruncation header in the DMLOptions Class.



          Order record = new Order(...);
          Database.DMLOptions opt = new Database.DMLOptions();
          opt.allowFieldTruncation = true;
          Database.insert(record, opt);


          If you're dong this from elsewhere (e.g. the API), there are similar headers you can use for allowFieldTruncation to prevent errors from appearing when field values are too long, without additional code.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 17 at 9:37









          sfdcfox

          228k10176390




          228k10176390











          • I see. Is there a way to specify a concrete field? I am assuming that by using the DMLOption approach will truncate all the fields if required.
            – Cuban coffee
            Aug 17 at 9:56







          • 1




            @Cubancoffee Yes, it will allow all fields to truncate. If you need more specific behavior, you would have to do it one-off.
            – sfdcfox
            Aug 17 at 9:57
















          • I see. Is there a way to specify a concrete field? I am assuming that by using the DMLOption approach will truncate all the fields if required.
            – Cuban coffee
            Aug 17 at 9:56







          • 1




            @Cubancoffee Yes, it will allow all fields to truncate. If you need more specific behavior, you would have to do it one-off.
            – sfdcfox
            Aug 17 at 9:57















          I see. Is there a way to specify a concrete field? I am assuming that by using the DMLOption approach will truncate all the fields if required.
          – Cuban coffee
          Aug 17 at 9:56





          I see. Is there a way to specify a concrete field? I am assuming that by using the DMLOption approach will truncate all the fields if required.
          – Cuban coffee
          Aug 17 at 9:56





          1




          1




          @Cubancoffee Yes, it will allow all fields to truncate. If you need more specific behavior, you would have to do it one-off.
          – sfdcfox
          Aug 17 at 9:57




          @Cubancoffee Yes, it will allow all fields to truncate. If you need more specific behavior, you would have to do it one-off.
          – sfdcfox
          Aug 17 at 9:57

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f229209%2faccommodate-the-length-of-a-string-value-to-prevent-the-string-too-long-issue%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?