Accommodate the length of a string value to prevent the STRING_TOO_LONG issue
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
4
down vote
favorite
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
add a comment |Â
up vote
4
down vote
favorite
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
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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
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
apex fields string
edited Aug 18 at 1:09
Peter Mortensen
23117
23117
asked Aug 17 at 9:28
Cuban coffee
538213
538213
add a comment |Â
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password