• Kapil_Khandelwal
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 2
    Replies
Hi,
I was wondering,  can we stop creating instances while there are instances already running of the apex class?

Thanks
Shweta.
I want to schedule an apex class using System.schedule.

This is the class I need to schedule. (ExampleHelpera.pxc)
public class ExampleHelper {
    
    @future(callout=true)
    public static void makeWebserviceCallout(){
        
       //logic goes here.

   }
}

This is the class that implements schedulable and calls the apex class. (ScheduleTest.apxc)
public class ScheduleTest implements Schedulable, Database.AllowsCallouts, Database.Batchable<sObject> {
    
    public void execute(SchedulableContext SC) {
        Database.executebatch(new ScheduleTest());
    }
    
    public Iterable<sObject> start(Database.Batchablecontext BC){
        if( !System.isFuture()) {
            ExampleHelper.makeWebserviceCallout();
        }
        
        
        return null;
    }
    
    public void execute(Database.BatchableContext BC, List<sObject> scope){  
        
    }
    
    public void finish(Database.BatchableContext info){
        
    }
    
}


Now I try Schedule the above code using following:
 
ScheduleTest st = new ScheduleTest();
String sch=  '0 20 18 16 8 ?';
String jobId=System.schedule('Test Schedule', sch, st);

After running the above code snippet in Execute Anonymous Window, the schedule is being created (as I had verified it Setup > jobs > Scheduled jobs)
But the logic inside the apex class is not being executed.
I get the following error - Future method cannot be called from a future or batch method: ExampleHelper.makeWebserviceCallout()

But when I run my logic code in Execute Anonymous Window, it gets executed without any error.


Kindly help me out with the same.
Thanks in advance.
I am willing to upload JSON data using BULK api. I know how to upload CSV data using BULK api. 

I referred to the steps mentioned here - https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_quickstart_requests_intro.htm

My login.txt looks like this (it is not giving any error):
?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<n1:login xmlns:n1="urn:partner.soap.sforce.com">
<n1:username><my_username></n1:username>
<n1:password><my_pasword></n1:password>
</n1:login>
</env:Body>
</env:Envelope>

job.txt is as follows:
 
<?xml version="1.0" encoding="UTF-8"?>
<jobInfo
   xmlns="http://www.force.com/2009/06/asyncapi/dataload">
 <operation>insert</operation>
 <object>Account</object>
 <contentType>JSON</contentType>
</jobInfo>

Make a note that I had changed contentType to "JSON".

Now when I run the following curl command to create json job:
 
curl https://<my_instance>.salesforce.com/services/async/43.0/job -H "X-SFDC-Session: <my_sessionId>" -H "Content-Type: application-json; charset=UTF-8" -d @job.txt

I get an error - {"exceptionCode":"InvalidJob","exceptionMessage":"Unable to parse Job"}

And when I run the following curl command (Note the Content-Type has been changed here): 
 
curl https://<my_instance>.salesforce.com/services/async/43.0/job -H "X-SFDC-Session: <mu_sessionId>" -H "Content-Type: application-xml; charset=UTF-8" -d @job.txt


The job gets created but it is of type "CSV". So when I try to add json data into this job by creating a batch, I get an error - Wrong content-type for batch (application/json), job is of type: text/csv

Please help me on how to create a job with Content-Type as JSON and how to upload JSON data into that job.

Thanks in advance.

 
I am confused between the two. When to use what!!! 
Please explain the difference between the two. Also present a use case where we can use process builder and not triggers and vice-versa.

Thanks in advance.
Hi,
I am willing to prepare for Salesforce Platform Developer 2. From where should I start?
Please provide some resources for the same.

Thanks in advance.
When I run following query in Query Editor of Developer Console, I get the expected output.
 
FIND {old} IN ALL FIELDS RETURNING Shala, Id, Contact(FirstName)
But when I run same query in my Apex code, I get an error.
 
List<List<SObject>> oldList = [FIND {old} IN ALL FIELDS RETURNING Shala, Id, Contact(FirstName)];

Kindly help me regarding the same.


Thanks in advance.

 
Hi,
While creating New Custom Object Tab, there is a field named Tab Style which is to be selected from a bunch of icons.
What is the significance of this Tab style? Whichever icon I choose, I don't feel any difference.

User-added image
 
I want to schedule an apex class using System.schedule.

This is the class I need to schedule. (ExampleHelpera.pxc)
public class ExampleHelper {
    
    @future(callout=true)
    public static void makeWebserviceCallout(){
        
       //logic goes here.

   }
}

This is the class that implements schedulable and calls the apex class. (ScheduleTest.apxc)
public class ScheduleTest implements Schedulable, Database.AllowsCallouts, Database.Batchable<sObject> {
    
    public void execute(SchedulableContext SC) {
        Database.executebatch(new ScheduleTest());
    }
    
    public Iterable<sObject> start(Database.Batchablecontext BC){
        if( !System.isFuture()) {
            ExampleHelper.makeWebserviceCallout();
        }
        
        
        return null;
    }
    
    public void execute(Database.BatchableContext BC, List<sObject> scope){  
        
    }
    
    public void finish(Database.BatchableContext info){
        
    }
    
}


Now I try Schedule the above code using following:
 
ScheduleTest st = new ScheduleTest();
String sch=  '0 20 18 16 8 ?';
String jobId=System.schedule('Test Schedule', sch, st);

After running the above code snippet in Execute Anonymous Window, the schedule is being created (as I had verified it Setup > jobs > Scheduled jobs)
But the logic inside the apex class is not being executed.
I get the following error - Future method cannot be called from a future or batch method: ExampleHelper.makeWebserviceCallout()

But when I run my logic code in Execute Anonymous Window, it gets executed without any error.


Kindly help me out with the same.
Thanks in advance.
Hi,
I was wondering,  can we stop creating instances while there are instances already running of the apex class?

Thanks
Shweta.