You need to sign in to do that
Don't have an account?
marys pinda
Create Document Using Schedulable
Hello,
I have a code which gets information from a file-URL and creates a Document within the Salesforce.
I wish he created the document on the 10 am and then I used Schedulable.
But he has a problem and does not create the document.
Someone help me please!.
I have a code which gets information from a file-URL and creates a Document within the Salesforce.
I wish he created the document on the 10 am and then I used Schedulable.
But he has a problem and does not create the document.
Someone help me please!.
global class Test implements System.Schedulable { global void execute(SchedulableContext sc) { getFile(); } public void getFile(){ Http h = new Http(); HttpRequest req = new HttpRequest(); string firstImageURL = 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL,IBM&f=sl1d1t1c1ohgv&e=.csv'; firstImageURL = firstImageURL.replace(' ', '%20'); req.setEndpoint(firstImageURL); req.setMethod('GET'); req.setHeader('Content-Type', 'text/csv'); req.setCompressed(true); req.setTimeout(60000); HttpResponse res = null; res = h.send(req); string responseValue = ''; responseValue = res.getBody(); system.debug('Response Body for File: ' + responseValue); blob image = res.getBodyAsBlob(); Document mydoc = new Document(); mydoc.Name = 'update today'; mydoc.Type = 'csv'; mydoc.folderid = UserInfo.getUserId(); mydoc.Body = image; insert mydoc; } }Thank you,
Nothing happens ...
The code is correct, right?
Also do not understand where is the error ...
I don't see this being exected..
TESTED:
RESULT:
30.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
Execute Anonymous: public class testeReturn{
Execute Anonymous: public void getFile(){
Execute Anonymous: Http h = new Http();
Execute Anonymous: HttpRequest req = new HttpRequest();
Execute Anonymous: string firstImageURL = 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL,IBM&f=sl1d1t1c1ohgv&e=.csv';
Execute Anonymous: firstImageURL = firstImageURL.replace(' ', '%20');
Execute Anonymous: req.setEndpoint(firstImageURL);
Execute Anonymous: req.setMethod('GET');
Execute Anonymous: req.setHeader('Content-Type', 'text/csv');
Execute Anonymous: req.setCompressed(true);
Execute Anonymous: req.setTimeout(60000);
Execute Anonymous:
Execute Anonymous: HttpResponse res = null;
Execute Anonymous: res = h.send(req);
Execute Anonymous: string responseValue = '';
Execute Anonymous: responseValue = res.getBody();
Execute Anonymous: system.debug('Response Body for File: ' + responseValue);
Execute Anonymous: blob image = res.getBodyAsBlob();
Execute Anonymous:
Execute Anonymous: system.debug('##########' + image);
Execute Anonymous:
Execute Anonymous: }
Execute Anonymous: }
14:18:40.027 (27200899)|EXECUTION_STARTED
14:18:40.027 (27211962)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
14:18:40.027 (27523181)|HEAP_ALLOCATE|[71]|Bytes:3
14:18:40.027 (27570380)|HEAP_ALLOCATE|[76]|Bytes:152
14:18:40.027 (27606215)|HEAP_ALLOCATE|[272]|Bytes:408
14:18:40.027 (27651122)|HEAP_ALLOCATE|[285]|Bytes:408
14:18:40.027 (27694341)|HEAP_ALLOCATE|[379]|Bytes:48
14:18:40.027 (27750211)|HEAP_ALLOCATE|[131]|Bytes:6
14:18:40.027 (27901232)|STATEMENT_EXECUTE|[1]
14:18:40.027 (27910863)|STATEMENT_EXECUTE|[1]
14:18:40.139 (27962974)|CUMULATIVE_LIMIT_USAGE
14:18:40.139|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10
14:18:40.139|CUMULATIVE_LIMIT_USAGE_END
14:18:40.028 (28017586)|CODE_UNIT_FINISHED|execute_anonymous_apex
14:18:40.028 (28034274)|EXECUTION_FINISHED
What do I do? Thank you
TESTED:
RESULT:
0.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
Execute Anonymous: public class testeReturn {
Execute Anonymous:
Execute Anonymous:
Execute Anonymous: public void getFile(){
Execute Anonymous: Http h = new Http();
Execute Anonymous: HttpRequest req = new HttpRequest();
Execute Anonymous: string firstImageURL = 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL,IBM&f=sl1d1t1c1ohgv&e=.csv';
Execute Anonymous: firstImageURL = firstImageURL.replace(' ', '%20');
Execute Anonymous: req.setEndpoint(firstImageURL);
Execute Anonymous: req.setMethod('GET');
Execute Anonymous: req.setHeader('Content-Type', 'text/csv');
Execute Anonymous: req.setCompressed(true);
Execute Anonymous: req.setTimeout(60000);
Execute Anonymous:
Execute Anonymous: HttpResponse res = null;
Execute Anonymous: res = h.send(req);
Execute Anonymous: string responseValue = '';
Execute Anonymous: responseValue = res.getBody();
Execute Anonymous: system.debug('Response Body for File: ' + responseValue);
Execute Anonymous: blob image = res.getBodyAsBlob();
Execute Anonymous:
Execute Anonymous: Document mydoc = new Document();
Execute Anonymous: mydoc.Name = 'update today';
Execute Anonymous: mydoc.Type = 'csv';
Execute Anonymous: mydoc.folderid = UserInfo.getUserId();
Execute Anonymous: mydoc.Body = image;
Execute Anonymous: insert mydoc;
Execute Anonymous: }
Execute Anonymous: }
15:16:38.034 (34918563)|EXECUTION_STARTED
15:16:38.034 (34928206)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
15:16:38.035 (35180319)|HEAP_ALLOCATE|[71]|Bytes:3
15:16:38.035 (35216635)|HEAP_ALLOCATE|[76]|Bytes:152
15:16:38.035 (35238502)|HEAP_ALLOCATE|[272]|Bytes:408
15:16:38.035 (35265174)|HEAP_ALLOCATE|[285]|Bytes:408
15:16:38.035 (35290284)|HEAP_ALLOCATE|[379]|Bytes:48
15:16:38.035 (35328947)|HEAP_ALLOCATE|[131]|Bytes:6
15:16:38.035 (35359684)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:2
15:16:38.035 (35433118)|STATEMENT_EXECUTE|[1]
15:16:38.035 (35437668)|STATEMENT_EXECUTE|[1]
15:16:38.097 (35481512)|CUMULATIVE_LIMIT_USAGE
15:16:38.097|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10
15:16:38.097|CUMULATIVE_LIMIT_USAGE_END
15:16:38.035 (35525801)|CODE_UNIT_FINISHED|execute_anonymous_apex
15:16:38.035 (35534566)|EXECUTION_FINISHED
What do I do? Thank you