How to determine Platform Event Size in Apex to ensure to be within < 1 MBGovernor limits in scheduling ScheduledApex jobs - how much and where to find them?Can you query a Platform event?Apex Rest Vs Platform Events for Inbound SF integration which one to choose?Publishing platform event using trigger?Platform Event ReplayId - metadata says it is a String of length 1000 but evidence shows it as an integerPlatform Event Apex trigger limits exception - where does it go?View Platform Event External SubscribersPlatform Event batchingError handling when publishing platform events403::Organization total events daily limit exceeded
Linux ext4 restore file and directory access rights after bad backup/restore
What are my hardware upgrade optoins for a late 2009 iMac?
Improving an O(N^2) function (all entities iterating over all other entities)
Heatsink on underside of PCB
Equality of complex numbers in general
How to get a type of "screech" on guitar
Brute-force the switchboard
Transistor power dissipation rating
Could a US citizen born through "birth tourism" become President?
What's a German word for »Sandbagger«?
How was Luke's prosthetic hand in Episode V filmed?
Extract the attribute names from a large number of Shapefiles
Is encryption still applied if you ignore the SSL certificate warning for self-signed certs?
Making a Dataset that emulates `ls -tlra`?
When a ball on a rope swings in a circle, is there both centripetal force and tension force?
Flashing the ESP8266 12F from raspberry
Demographic consequences of closed loop reincarnation
How to not confuse readers with simultaneous events?
Why should fork() have been designed to return a file descriptor?
Applying for jobs with an obvious scar
Three Subway Escalators
Function over a list that depends on the index
Does unblocking power bar outlets through short extension cords increase fire risk?
How to tell readers that I know my story is factually incorrect?
How to determine Platform Event Size in Apex to ensure to be within
Governor limits in scheduling ScheduledApex jobs - how much and where to find them?Can you query a Platform event?Apex Rest Vs Platform Events for Inbound SF integration which one to choose?Publishing platform event using trigger?Platform Event ReplayId - metadata says it is a String of length 1000 but evidence shows it as an integerPlatform Event Apex trigger limits exception - where does it go?View Platform Event External SubscribersPlatform Event batchingError handling when publishing platform events403::Organization total events daily limit exceeded
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
The documentation on Platform event states:
The maximum event message size that you can publish is 1 MB.
Is there a native and reliable way in Apex to check whether the Platform Event I am about to publish falls within this limit?
Which parts of the event need to be considered for this check? Only field contents or also describe information about the field (i.e. is length of a custom field's api name a factor?). What is exactly considered part of the event message?
governorlimits platform-event
add a comment |
The documentation on Platform event states:
The maximum event message size that you can publish is 1 MB.
Is there a native and reliable way in Apex to check whether the Platform Event I am about to publish falls within this limit?
Which parts of the event need to be considered for this check? Only field contents or also describe information about the field (i.e. is length of a custom field's api name a factor?). What is exactly considered part of the event message?
governorlimits platform-event
Note also that if SFDC is consuming these events, the trigger batch size can be as large as 2000 which of course would blow up Heap. There are new ways in Summer 19 to mitigate this with setResumeCheckpoint method
– cropredy
8 hours ago
add a comment |
The documentation on Platform event states:
The maximum event message size that you can publish is 1 MB.
Is there a native and reliable way in Apex to check whether the Platform Event I am about to publish falls within this limit?
Which parts of the event need to be considered for this check? Only field contents or also describe information about the field (i.e. is length of a custom field's api name a factor?). What is exactly considered part of the event message?
governorlimits platform-event
The documentation on Platform event states:
The maximum event message size that you can publish is 1 MB.
Is there a native and reliable way in Apex to check whether the Platform Event I am about to publish falls within this limit?
Which parts of the event need to be considered for this check? Only field contents or also describe information about the field (i.e. is length of a custom field's api name a factor?). What is exactly considered part of the event message?
governorlimits platform-event
governorlimits platform-event
edited 8 hours ago
Christian Szandor Knapp
asked 9 hours ago
Christian Szandor KnappChristian Szandor Knapp
1,7411 gold badge8 silver badges29 bronze badges
1,7411 gold badge8 silver badges29 bronze badges
Note also that if SFDC is consuming these events, the trigger batch size can be as large as 2000 which of course would blow up Heap. There are new ways in Summer 19 to mitigate this with setResumeCheckpoint method
– cropredy
8 hours ago
add a comment |
Note also that if SFDC is consuming these events, the trigger batch size can be as large as 2000 which of course would blow up Heap. There are new ways in Summer 19 to mitigate this with setResumeCheckpoint method
– cropredy
8 hours ago
Note also that if SFDC is consuming these events, the trigger batch size can be as large as 2000 which of course would blow up Heap. There are new ways in Summer 19 to mitigate this with setResumeCheckpoint method
– cropredy
8 hours ago
Note also that if SFDC is consuming these events, the trigger batch size can be as large as 2000 which of course would blow up Heap. There are new ways in Summer 19 to mitigate this with setResumeCheckpoint method
– cropredy
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Maximum size allowed is 1048576 bytes (1.05MB)
When you exceed the limit, you will get below message:
(Database.Error[getFields=();getMessage=The event payload size of 1179064 bytes exceeds the maximum allowed size of 1048576 bytes;getStatusCode=PAYLOAD_SIZE_EXCEEDED;])
TESTING:
Create a platform event POC_PE__e and create 9 long text fields and use below apex method:
public static void publish()
String str = '1234567890', longStr = '';
for(Integer i=0; i<100; i++) str+='1234567890';
for(Integer i=0; i<131; i++) longStr+=str;
longStr = longStr.left(131000);
System.debug(poc.getBytesSize(longStr));
POC_PE__e pe = new POC_PE__e(Long_String__c=longStr,
Long_String2__c=longStr,
Long_String3__c=longStr,
Long_String4__c=longStr,
Long_String5__c=longStr,
Long_String6__c=longStr,
Long_String7__c=longStr,
Long_String8__c=longStr,
Long_String9__c=longStr
);
System.debug(JSON.serialize(pe));
String APIs = '"attributestypePOC_PE__eLong_String__cLong_String2__cLong_String3__cLong_String4__cLong_String5__cLong_String6__cLong_String7__cLong_String8__cLong_String9__c"';
System.debug(poc.getBytesSize(JSON.serialize(pe))-poc.getBytesSize(APIs)); //1179064 bytes
Database.SaveResult sr = EventBus.publish(pe);
if(sr.isSuccess()) System.debug('SUCCESS => '+sr.success);
else System.debug('ERROR => '+sr.getErrors());
Long_String__c, Long_String2__c.... are event fields.
Solution:
Use this method to get string bytes size (used in example above)
public static Integer getBytesSize(String str)
Blob myBlob = Blob.valueof(str);
return myBlob.size();
Got to this by using https://mothereff.in/byte-counter.
Number of chars is same as number of bytes. Note: we get exact bytes size (1179064 bytes) shown in error message (1179064 bytes).
Conclusion:
Salesforce serialises the event object(s) for transmitting to various destinations and deserialises before delivering. Only data is calculated for message size and not field API or Object API names.
Additional info:
Same is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record page when so many formula,lookup,rich text fields are included in page layout
New contributor
salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thank you. I have used your feedback to clarify my question - which parts of a platform event need to be considered for the calculation.
– Christian Szandor Knapp
8 hours ago
I think salesforce stringifies/serialises the object(s) (as is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record home page when so many formula,lookup,rich text area fields are included). So just before publishing event, you can check the size of serialised object(s) - by using JSON.serialize
– salesforcesas
8 hours ago
add a comment |
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
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f270235%2fhow-to-determine-platform-event-size-in-apex-to-ensure-to-be-within-1-mb%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
Maximum size allowed is 1048576 bytes (1.05MB)
When you exceed the limit, you will get below message:
(Database.Error[getFields=();getMessage=The event payload size of 1179064 bytes exceeds the maximum allowed size of 1048576 bytes;getStatusCode=PAYLOAD_SIZE_EXCEEDED;])
TESTING:
Create a platform event POC_PE__e and create 9 long text fields and use below apex method:
public static void publish()
String str = '1234567890', longStr = '';
for(Integer i=0; i<100; i++) str+='1234567890';
for(Integer i=0; i<131; i++) longStr+=str;
longStr = longStr.left(131000);
System.debug(poc.getBytesSize(longStr));
POC_PE__e pe = new POC_PE__e(Long_String__c=longStr,
Long_String2__c=longStr,
Long_String3__c=longStr,
Long_String4__c=longStr,
Long_String5__c=longStr,
Long_String6__c=longStr,
Long_String7__c=longStr,
Long_String8__c=longStr,
Long_String9__c=longStr
);
System.debug(JSON.serialize(pe));
String APIs = '"attributestypePOC_PE__eLong_String__cLong_String2__cLong_String3__cLong_String4__cLong_String5__cLong_String6__cLong_String7__cLong_String8__cLong_String9__c"';
System.debug(poc.getBytesSize(JSON.serialize(pe))-poc.getBytesSize(APIs)); //1179064 bytes
Database.SaveResult sr = EventBus.publish(pe);
if(sr.isSuccess()) System.debug('SUCCESS => '+sr.success);
else System.debug('ERROR => '+sr.getErrors());
Long_String__c, Long_String2__c.... are event fields.
Solution:
Use this method to get string bytes size (used in example above)
public static Integer getBytesSize(String str)
Blob myBlob = Blob.valueof(str);
return myBlob.size();
Got to this by using https://mothereff.in/byte-counter.
Number of chars is same as number of bytes. Note: we get exact bytes size (1179064 bytes) shown in error message (1179064 bytes).
Conclusion:
Salesforce serialises the event object(s) for transmitting to various destinations and deserialises before delivering. Only data is calculated for message size and not field API or Object API names.
Additional info:
Same is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record page when so many formula,lookup,rich text fields are included in page layout
New contributor
salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thank you. I have used your feedback to clarify my question - which parts of a platform event need to be considered for the calculation.
– Christian Szandor Knapp
8 hours ago
I think salesforce stringifies/serialises the object(s) (as is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record home page when so many formula,lookup,rich text area fields are included). So just before publishing event, you can check the size of serialised object(s) - by using JSON.serialize
– salesforcesas
8 hours ago
add a comment |
Maximum size allowed is 1048576 bytes (1.05MB)
When you exceed the limit, you will get below message:
(Database.Error[getFields=();getMessage=The event payload size of 1179064 bytes exceeds the maximum allowed size of 1048576 bytes;getStatusCode=PAYLOAD_SIZE_EXCEEDED;])
TESTING:
Create a platform event POC_PE__e and create 9 long text fields and use below apex method:
public static void publish()
String str = '1234567890', longStr = '';
for(Integer i=0; i<100; i++) str+='1234567890';
for(Integer i=0; i<131; i++) longStr+=str;
longStr = longStr.left(131000);
System.debug(poc.getBytesSize(longStr));
POC_PE__e pe = new POC_PE__e(Long_String__c=longStr,
Long_String2__c=longStr,
Long_String3__c=longStr,
Long_String4__c=longStr,
Long_String5__c=longStr,
Long_String6__c=longStr,
Long_String7__c=longStr,
Long_String8__c=longStr,
Long_String9__c=longStr
);
System.debug(JSON.serialize(pe));
String APIs = '"attributestypePOC_PE__eLong_String__cLong_String2__cLong_String3__cLong_String4__cLong_String5__cLong_String6__cLong_String7__cLong_String8__cLong_String9__c"';
System.debug(poc.getBytesSize(JSON.serialize(pe))-poc.getBytesSize(APIs)); //1179064 bytes
Database.SaveResult sr = EventBus.publish(pe);
if(sr.isSuccess()) System.debug('SUCCESS => '+sr.success);
else System.debug('ERROR => '+sr.getErrors());
Long_String__c, Long_String2__c.... are event fields.
Solution:
Use this method to get string bytes size (used in example above)
public static Integer getBytesSize(String str)
Blob myBlob = Blob.valueof(str);
return myBlob.size();
Got to this by using https://mothereff.in/byte-counter.
Number of chars is same as number of bytes. Note: we get exact bytes size (1179064 bytes) shown in error message (1179064 bytes).
Conclusion:
Salesforce serialises the event object(s) for transmitting to various destinations and deserialises before delivering. Only data is calculated for message size and not field API or Object API names.
Additional info:
Same is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record page when so many formula,lookup,rich text fields are included in page layout
New contributor
salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thank you. I have used your feedback to clarify my question - which parts of a platform event need to be considered for the calculation.
– Christian Szandor Knapp
8 hours ago
I think salesforce stringifies/serialises the object(s) (as is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record home page when so many formula,lookup,rich text area fields are included). So just before publishing event, you can check the size of serialised object(s) - by using JSON.serialize
– salesforcesas
8 hours ago
add a comment |
Maximum size allowed is 1048576 bytes (1.05MB)
When you exceed the limit, you will get below message:
(Database.Error[getFields=();getMessage=The event payload size of 1179064 bytes exceeds the maximum allowed size of 1048576 bytes;getStatusCode=PAYLOAD_SIZE_EXCEEDED;])
TESTING:
Create a platform event POC_PE__e and create 9 long text fields and use below apex method:
public static void publish()
String str = '1234567890', longStr = '';
for(Integer i=0; i<100; i++) str+='1234567890';
for(Integer i=0; i<131; i++) longStr+=str;
longStr = longStr.left(131000);
System.debug(poc.getBytesSize(longStr));
POC_PE__e pe = new POC_PE__e(Long_String__c=longStr,
Long_String2__c=longStr,
Long_String3__c=longStr,
Long_String4__c=longStr,
Long_String5__c=longStr,
Long_String6__c=longStr,
Long_String7__c=longStr,
Long_String8__c=longStr,
Long_String9__c=longStr
);
System.debug(JSON.serialize(pe));
String APIs = '"attributestypePOC_PE__eLong_String__cLong_String2__cLong_String3__cLong_String4__cLong_String5__cLong_String6__cLong_String7__cLong_String8__cLong_String9__c"';
System.debug(poc.getBytesSize(JSON.serialize(pe))-poc.getBytesSize(APIs)); //1179064 bytes
Database.SaveResult sr = EventBus.publish(pe);
if(sr.isSuccess()) System.debug('SUCCESS => '+sr.success);
else System.debug('ERROR => '+sr.getErrors());
Long_String__c, Long_String2__c.... are event fields.
Solution:
Use this method to get string bytes size (used in example above)
public static Integer getBytesSize(String str)
Blob myBlob = Blob.valueof(str);
return myBlob.size();
Got to this by using https://mothereff.in/byte-counter.
Number of chars is same as number of bytes. Note: we get exact bytes size (1179064 bytes) shown in error message (1179064 bytes).
Conclusion:
Salesforce serialises the event object(s) for transmitting to various destinations and deserialises before delivering. Only data is calculated for message size and not field API or Object API names.
Additional info:
Same is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record page when so many formula,lookup,rich text fields are included in page layout
New contributor
salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Maximum size allowed is 1048576 bytes (1.05MB)
When you exceed the limit, you will get below message:
(Database.Error[getFields=();getMessage=The event payload size of 1179064 bytes exceeds the maximum allowed size of 1048576 bytes;getStatusCode=PAYLOAD_SIZE_EXCEEDED;])
TESTING:
Create a platform event POC_PE__e and create 9 long text fields and use below apex method:
public static void publish()
String str = '1234567890', longStr = '';
for(Integer i=0; i<100; i++) str+='1234567890';
for(Integer i=0; i<131; i++) longStr+=str;
longStr = longStr.left(131000);
System.debug(poc.getBytesSize(longStr));
POC_PE__e pe = new POC_PE__e(Long_String__c=longStr,
Long_String2__c=longStr,
Long_String3__c=longStr,
Long_String4__c=longStr,
Long_String5__c=longStr,
Long_String6__c=longStr,
Long_String7__c=longStr,
Long_String8__c=longStr,
Long_String9__c=longStr
);
System.debug(JSON.serialize(pe));
String APIs = '"attributestypePOC_PE__eLong_String__cLong_String2__cLong_String3__cLong_String4__cLong_String5__cLong_String6__cLong_String7__cLong_String8__cLong_String9__c"';
System.debug(poc.getBytesSize(JSON.serialize(pe))-poc.getBytesSize(APIs)); //1179064 bytes
Database.SaveResult sr = EventBus.publish(pe);
if(sr.isSuccess()) System.debug('SUCCESS => '+sr.success);
else System.debug('ERROR => '+sr.getErrors());
Long_String__c, Long_String2__c.... are event fields.
Solution:
Use this method to get string bytes size (used in example above)
public static Integer getBytesSize(String str)
Blob myBlob = Blob.valueof(str);
return myBlob.size();
Got to this by using https://mothereff.in/byte-counter.
Number of chars is same as number of bytes. Note: we get exact bytes size (1179064 bytes) shown in error message (1179064 bytes).
Conclusion:
Salesforce serialises the event object(s) for transmitting to various destinations and deserialises before delivering. Only data is calculated for message size and not field API or Object API names.
Additional info:
Same is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record page when so many formula,lookup,rich text fields are included in page layout
New contributor
salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 4 hours ago
New contributor
salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 8 hours ago
salesforcesassalesforcesas
2765 bronze badges
2765 bronze badges
New contributor
salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thank you. I have used your feedback to clarify my question - which parts of a platform event need to be considered for the calculation.
– Christian Szandor Knapp
8 hours ago
I think salesforce stringifies/serialises the object(s) (as is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record home page when so many formula,lookup,rich text area fields are included). So just before publishing event, you can check the size of serialised object(s) - by using JSON.serialize
– salesforcesas
8 hours ago
add a comment |
Thank you. I have used your feedback to clarify my question - which parts of a platform event need to be considered for the calculation.
– Christian Szandor Knapp
8 hours ago
I think salesforce stringifies/serialises the object(s) (as is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record home page when so many formula,lookup,rich text area fields are included). So just before publishing event, you can check the size of serialised object(s) - by using JSON.serialize
– salesforcesas
8 hours ago
Thank you. I have used your feedback to clarify my question - which parts of a platform event need to be considered for the calculation.
– Christian Szandor Knapp
8 hours ago
Thank you. I have used your feedback to clarify my question - which parts of a platform event need to be considered for the calculation.
– Christian Szandor Knapp
8 hours ago
I think salesforce stringifies/serialises the object(s) (as is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record home page when so many formula,lookup,rich text area fields are included). So just before publishing event, you can check the size of serialised object(s) - by using JSON.serialize
– salesforcesas
8 hours ago
I think salesforce stringifies/serialises the object(s) (as is the case with lightning platform - got confirmation from salesforce support. Thats the reason you see error message on object record home page when so many formula,lookup,rich text area fields are included). So just before publishing event, you can check the size of serialised object(s) - by using JSON.serialize
– salesforcesas
8 hours ago
add a comment |
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.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f270235%2fhow-to-determine-platform-event-size-in-apex-to-ensure-to-be-within-1-mb%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
Note also that if SFDC is consuming these events, the trigger batch size can be as large as 2000 which of course would blow up Heap. There are new ways in Summer 19 to mitigate this with setResumeCheckpoint method
– cropredy
8 hours ago