Posts

How to download the files using URL from salesforce

Note:   To download the file, require the  Content Version record Ids For Single File Use the below URL to download the single file from the salesforce. URL :    https://<YOUR_SFDC_BASE_URL>/sfc/servlet.shepherd/version/download/068XXXXXXXXXXXX   String idCntDoc = '068XXXXXXXXXXXX' ; String strURL = URL.getSalesforceBaseUrl().toExternalForm() + '/sfc/servlet.shepherd/version/download/' + idCntDoc; System.debug( 'URL ===> ' +strURL); For Multiple Files URL:  https://<YOUR_SFDC_BASE_URL>/sfc/servlet.shepherd/version/download/068XXXXXXXXXXXX/068XXXXXXXXXXXX above URL downloads the files in ZIP folder list<String> lstCntVersionIds = new list<String>{ '068XXXXXXXXXXXX' , '068XXXXXXXXXXXX' }; String strURL = URL.getSalesforceBaseUrl().toExternalForm() + '/sfc/servlet.shepherd/version/download/' ; for (String iterator : lstCntVersionIds) { strURL += iterator + '/' ; } strURL = strURL.removeEnd( '/...

File Preview in Visualforce salesforce

Ever notice how cool, the preview functionality in Salesforce Chatter is? Well, you can reuse the same component that Salesforce does.   Chatter uses a Shockwave Plugin to preview files. We can make use of the same plugin using the  <embed>  tag in VisualForce. Here's the tag: <embed src="/_swf/190003/sfc/flex/DocViewer.swf" flashvars="shepherd_prefix=/sfc/servlet.shepherd&v= <DocumentVersionId> &mode=chatter_bubble&in_tests=false" width="100%" height="100%" align="middle" id="renditionLarge" quality="high" bgcolor="#f3f3f3" name="renditionLarge" allowscriptaccess="always" allowfullscreen="true" pluginspage="http://www.adobe.com/go/getflashplayer" wmode="opaque" type="application/x-shockwave-flash"> The only thing you need to add to the link in the Document Version ID. (Not the Document ID) You get the Version ID f...

The Difference Between REST and SOAP APIs

This overview will help you understand the differences between REST and SOAP APIs, and how they are used in integrations. The words "web services" mean many things to people with different fields. For general users, it is about using online services, like surfing the internet, but for developers and webmasters, it has different meanings. Overall it is a broad term that tells us how the communication between two different set of devices or applications held over the World Wide Web (WWW). This communication system can be categorized into two types, namely Simple Object Access Protocol or SOAP, and Representational State Transfer or REST. Quite often both are considered to be the terms with same meanings but the how both works and what tools both use for communication purposes creates the fine line between two. Before highlighting the differences between two, it merits to discuss what both actually are. What Is a REST API? REST is basically an architectural style of the web serv...

System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop

This exception is talking about an “aggregate query” not an “aggregate function.” I had never heard the term “aggregate query” before, and I suspect you haven’t either. After hunting around, I found the relevant Salesforce documentation – Salesforce Apex Developer Guide: SOQL For Loops. The documentation explains that Salesforce might throw the System.QueryException when a query has a sub-query (this is the “aggregate query”), and our sub-query returns more than 200 child records. For example, if we have an Account with more than 200 AccountTeamMembers, we might get the exception when we run the following code with a query on Account with a sub-query for child AccountTeamMembers.  Code that could throw an exception if there are more than 200 child records: List<Account> accounts = [Select Id, (Select Id, AccountId , UserId From AccountTeamMembers) , (Select Id , OwnerId, AccountId from Opportunities) From Account]; for ( Account acc : accounts ) {     // Either...

How to run a scheduled job every 15 mins?

You can write a Batch Class and then Schedule it with the help of a scheduler.Let me explain it to you with the help of an example: BATCH CLASS  : global class test_BATCH implements Database.Batchable<sObject> { global (Database.QueryLocator | Iterable<sObject>)  start (Database.BatchableContext BC) { String query = 'SELECT Id,Name FROM Account'; return Database.getQueryLocator(query); } global void  execute (Database.BatchableContext BC, List<Account> scope) { for(Account a : scope){ a.Name = a.Name + 'Updated'; } update scope; } global void  finish (Database.BatchableContext BC) { } }   SCHEDULABLE CLASS : global class scheduledBatchable implements  Schedulable { global void execute(SchedulableContext sc) { test_BATCH b = new test_BATCH(); //Parameters of ExecuteBatch(context,BatchSize) database.executebatch(b,10); } } ***Note: if batch size is not mentioned it is 200 by default.   CUSTOM TIMING String time = '0 0 * * * ?'...

The Developer Console didn't set the DEVELOPER_LOG trace flag on your user. Having an active trace flag triggers debug logging. You have 1,978 MB of the maximum 1,000 MB of debug logs. Before you can edit trace flags, delete some debug logs.

1. In developer console, Select tab "Query Editor" at the bottom of the console. 2. Select check box "Use Tooling API". 3. Execute the below query: SELECT Id FROM ApexLog   4. Select All Rows. Click the first row and then press Shift button and click last row to select all the rows. Delete all rows using Delete button. https://help.salesforce.com/articleView?id=code_debug_log_delete.htm&type=5

Troubleshoot 'System.LimitException: Batchable instance is too big' error

If a batch apex class implements Database.Stateful, the instance state is stored in the database.  At this time we do a check against the size of the instance state and t he exception is thrown when the Apex Heap Size limit is exceeded. For synchronous Apex the heap size limit is 6 MB and for asynchronous Apex the limit is 12 MB.  This exception can obviously occur in a scenario where large collections are persistently maintained. Even if some chunks fail with this error, the batch job is completed. As per below lines in  Batch Apex Developer Guide   "If the first transaction succeeds but the second fails, the database updates made in the first transaction are not rolled back." To work around this issue, you can use the following steps: 1. Avoid using Database.Stateful 2. Reduce the amount of persistent data 3. Process less records per batch   In some cases Database.Stateful isn't being implemented or the steps above are not helpful in working around this e...