• ForceMantis (Amit Jain)
  • NEWBIE
  • 480 Points
  • Member since 2011
  • Senior Tech Lead
  • Metacube Software Pvt. Ltd.


  • Chatter
    Feed
  • 17
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 0
    Questions
  • 133
    Replies
I am trying to update the status of a lead from a task trigger if a certain task is completed. When testing my code the execution always seems to stop when I try to update the lead. I think this may be because in my test class the tasks are not assigned to a lead, but when I tried creating a sample lead to use I think I made a mistake because the test then gets 0% code coverage.
trigger TaskScheduler on Task (after insert, after update) {
    // Iterate through all tasks
    for(Task t : Trigger.new){
        // Schedule follow up task for completed tasks depending on task subject
        if(t.Status == 'Completed'){    
            if(t.Subject == 'Send Initial Email'){
                // update lead status
                Lead myLead = new Lead(Id = t.whoId);
                myLead.Id = t.whoId;
                myLead.Status = 'Working';
                update myLead;
                // schedule new task
                Task newTask = new Task(Subject = 'Make Initial Phone Call', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Make Initial Phone Call'){
                Task newTask = new Task(Subject = 'Send Email #2', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date(), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Send Email #2'){
                Task newTask = new Task(Subject = 'Make Phone Call #2', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Make Phone Call #2'){
                Task newTask = new Task(Subject = 'Send Email #3', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date(), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Send Email #3'){
                Task newTask = new Task(Subject = 'Make Phone Call #3', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            // When final task is completed, change lead status to 'unresponsive'
            } else if(t.Subject == 'Make Phone Call #3'){
                // update lead status
                Lead myLead2 = new Lead(Id = t.whoId);             
                myLead2.Id = t.whoId;     
                myLead2.Status = 'Unresponsive';
                update myLead2;
            }
        }    
    }
}

My test class so far:
@isTest
private class TestTaskScheduler {
    public static testMethod void validateScheduler(){
        // Start Test
        System.Test.startTest();
        Lead myLead = new Lead();
        String userId = UserInfo.getUserId();
        List<Task> taskList = new List<Task>();
        for(integer i = 0; i < 6; i++){
            Task t = new Task();
            t.OwnerId = userId;
            t.Subject = 'Send Initial Email';
            t.priority= 'Normal';
            t.status = 'Completed';
            t.description = 'Testing';
            t.ActivityDate = system.now().Date();
            t.whoId = myLead.Id;
            taskList.add(t);
        }
        taskList[1].Subject = 'Make Initial Phone Call';
        taskList[2].Subject = 'Send Email #2';
        taskList[3].Subject = 'Make Phone Call #2';
        taskList[4].Subject = 'Send Email #3';
        taskList[5].Subject = 'Make Phone Call #3';
        insert taskList;
        System.Test.stopTest(); 
    }
}

Thanks!
I have a VF page for new requests for sales support.  They choose what kind of request it is from a picklist. New Product, Pricing, Reports, ETC. Each of these have a set of minimum required information for us to complete the request.  Can I use an IF statement that will set the visibility and required status of the input object based on the input of that initial picklist value? or is there an easier way to do this?  I am fairly new to salesforce and visualforce coming from working with MS Access and sharepoints. 
I have a formula that pretty much works correct:

IF(ISNULL(dueDateTime__c), "YES",
( IF( ISNULL(closeDateTime__c), ( IF(dueDateTime__c >=  NOW(), "YES", "NO")),
( IF(dueDateTime__c >= closeDateTime__c, "YES", "NO"))
))
)
So far so good...however I have yet another condition I want to check.  

Effecively if the Completed Date is not null and Close Date is greater than or equal to Due Date, then the field is "YES".

So I came up with this:

IF(ISNULL(dueDateTime__c), "YES", 
	( IF( ISNULL(closeDateTime__c), ( IF(dueDateTime__c >= 	NOW(), "YES", "NO")), 
	( IF(dueDateTime__c >= closeDateTime__c, "YES", "NO")),
	( IF (AND( NOT(ISNULL(CompletedDate__c), (IF(closeDateTime__c >= dueDateTime__c, "YES", "NO")))))))))

However, I get the following error:

Error: Syntax error. Missing ')'

I'll spare you the details of all the gyrations I've gone through the the ')'.  Suffice it to say the cursor goes to the comma ( , ) after the (CompletedDate__c) field.

As always your help is always appreciated!  Thank you!

Hi there.  I have been working with the VisualForce "renderAs="pdf"" with my page.  The client has some requirements I need to meet.  I need to add the pdf to the Opportunity record in the notes and attachments related list.

I have found the following code:

 

Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename='+pdfName);

 This code is great because as soon as the user clicks on the link to my pdf rendered page it just opens the save dialog.  However, in addition to this I would like to insert the pdf as an attachment to the record it is related to. 

I found some code and got some help from the forum already about inserting the page as a new attachment but when the file attaches to the record I get an error from Adobe reader when I try to open it: 

ERROR: Adobe Reader could not open 'FILENAME.pdf' because it is either not a supported file type or because the file has been damaged (for, example, it was sent as an email attachment and wasn't correctly decoded).

My question is this: does the line of code above create an attachment, and if so, can't I just insert that into my related record instead of making a new attachment and using getContent() etc.?

 

Thanks!

 

  • April 25, 2013
  • Like
  • 0

Compile Error: Initial term of field expression must be a concrete SObject: String at line 20 column 59

 

trigger Update_AccountID on Account (after insert,after update) {

public list<AccountID__c > AID =new list<AccountID__c >();
public Map<string,String> Map_Types=new Map<string,String>();
set<string> Typevalue=new set<string>();
for(account a1:trigger.new){
Typevalue.add(a1.type);
}
Account_Running_Number__c []ARN_ids=[select Id,Running_Number__c,Type__c from Account_Running_Number__c where Type__c in:Typevalue];
for(Account_Running_Number__c AR1:ARN_ids){
Map_Types.put(AR1.Type__c,AR1.Type__c);
}

for(Account a2:trigger.new){
for(Account a3:trigger.old)
{
if(a2.Type=='Tour Agent' && a3.Type!='Tour Agent')
{
AccountID__c t1 = new AccountID__c();
t1.Account_Id__c='TA'+Map_Types.get(a2.Type).Running_Number__c;
t1.Type__c=a2.Type;
AID.add(t1);
}
}
}
Insert AID;
}

 

 

Compilation error giving how to solve!!!, The way i used MAP is some where wrong. Can any one suggest.

  • March 09, 2013
  • Like
  • 0

Hi ALL SFDC Experts,

 

I am new bee to  Batch Apex.No doc explains clearly these ...can any one  explain me

 

we have '  Execute()' Method:

 

what is the difference between these two methods and what does the highlighted ones are

 

global void execute(Database.Batchablecontext BC, List<sObject> Scope);

 

global void execute(Database.Batchablecontext BC, List<P>);

 


As I know 'BC' holds reference to the  'Batchablecontext ' object. But what are List<sObject> Scope and List<P>

 

In interview


 I have been asked which data type I use in execute method-- kept blank face?

 

And  what is the difference between sObject and object?

 

 

 

Thanks in Advance

  • March 09, 2013
  • Like
  • 0

Hi there

 

I want to create a trigger so that, when a record is inserted into object A,

 

that will create one or more records into object B (that has a lookup to object A)

 

and will create one or more records into object C (that has a lookup to object B)

 

My construct to insert the records into object B is straightforward:

 

for loop (for each records to be inserted to object B)

{

        ListVariable.add(a new instance of object B)

}

insert(ListVariable)

 

i.e. I first put all the records that I need to insert into object B into a list, and then call the insert.

 

To insert records into object C, I will need to get the Id of object B.

 

Now that I have created into object B, how do I retrieve the IDs of each record that I inserted into object B so I can finish the second part of the trigger?

 

Thanks

 

 

 

this is the trigger code: trigger InsertUpdateCon on ConTest__c (after insert, after update, before insert, before update) { if(Trigger.isAfter && Trigger.isInsert){ UpdateDateFromMaster accob= new UpdateDateFromMaster(Trigger.new); } } and this is class: public class UpdateDateFromMaster{ public UpdateDateFromMaster(List accTest){ Map accMap= new Map(); Set accId=new Set(); system.debug('#### map'+accTest); for(ConTest__c con: accTest){ accId.add(con.AccTest__c); } for(AccTest__c acc: [select Id,Name,Close_Date__c from AccTest__c where Id =:accId]){ accMap.put(acc.Id,acc); } system.debug('#### map'+accMap); Date Ob= date.today()+20; for(ConTest__c con: accTest){ if(accMap.containsKey(con.AccTest__c)){ accMap.get(con.AccTest__c).Close_Date__c=Ob; } } if(accMap != null){ update accMap.values(); } } }
  • August 15, 2012
  • Like
  • 0

Basically I need to do a recursive clone of an object and all it's children.

 

I was initially hoping to intercept the standard clone event using a trigger, and capture the clone variable in the query using:

 

URL.getCurrentRequestUrl().getQuery());

 

hoping to find "clone=1" somewhere in the string, but it only returns a null, so I am assuming there is a page redirect or such before the trigger is executed.

 

any suggestions on how to best catch the 'clone' so that I can do my thing and clone all the related items?

For a contact, you can click on the email field to send an email to that email address, and that functionality is automatically there. I want to know if there is a way to have that field become un click-able (as in you can't click it to send an email to that email address) when the Email Opt Out field is true. Does anyone know if that is possible?

I was trying to get the value of the inputcheckbox on click, it always return 'on' instead of 0 or 1. How to I get the value of the checkbox so that I can knw if it is checked or unchecked.

 

<apex:repeat value="{!phaseList}" var="p">
                    <apex:inputCheckbox id="chkbox" onclick="createTask('{!$Component.chkbox}')"/>
                    <apex:outputLabel for="chkbox" value="{!p.Name}"/><br/>
                </apex:repeat>

 

 

Hi,

 

Is it possible to create a custom object using APEX. This link says it cannot, was any changes deployed in the recent releases? Does any of you have any information on this?

 

Thanks,

Aravind

Hello friends,

 

I want to fetch more than 50000 contacts and want to process them, but I am not able to do that.

 

How can I use batch apex for this or is there any way other than batch apex?

 

Could you please help me to get through this.

 

Thanks in advance.

 

Pratty

  • March 10, 2012
  • Like
  • 0

Urgent : Can we create a List of all visualforce Pages names?

 

Please reply ASAP.

i have requirement where i need to check if apex:inputCheckbox is checked, and if it isn't then raise an alert saying that its not checked.

 <apex:inputCheckbox value="{!check}"/> 

I am raising the alert from a java script. i am using actionfunction to call a apex method after the alert is raised.

What i need is a way to check if the checkbox is checked or not in javascript

Thanks

Prady

hii,

 

  i have to create a page in which i select a folder and  then i have to show all list of templates in that folder.

but problem is that  in query i am only getting custom folders..not visual force forlders,  like   unfield public email template

 

tahnks

I am writing a trigger that should only fire is the created date of the object is after a certain date say august 1, 2011.

 

I am having the hardest time with the syntax of this conditional for my if statement.

 

any help would be greatly appreciated.

 

Thanks,

Phil

  • August 04, 2011
  • Like
  • 0
Hi Team,

I had a business case to run Batch class concurrently, I was successfully able to accomplish that by writing another Batch class which creates chunks of data and call main Batch class n number of times. Now I am trying to make that concurrent class generic so that it can work with any sObject and be able to call any Batch class whose name I will be passing through custom setting.

I am using Type Class to implement this (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_type.htm%23apex_methods_system_type)

I have used this in past and it works fine with Apex classes but in case of Batch class I am getting below error:
Compile Error: Argument must be an object that implements Database.Batchable at line 87 column 17
 
Type classType = Type.forName('MyBatchClassName');
MyInterFaceName obj = (MyInterFaceName)classType.newInstance();
obj.runBatchConcurrently(); // This is the method which I declared in Interface and implemented in Batch class               
system.debug('### obj'+obj); // In debug I am able to see instance of my Batch class
database.executeBatch(obj, 200); // Compile error is coming here

 
I am trying to update the status of a lead from a task trigger if a certain task is completed. When testing my code the execution always seems to stop when I try to update the lead. I think this may be because in my test class the tasks are not assigned to a lead, but when I tried creating a sample lead to use I think I made a mistake because the test then gets 0% code coverage.
trigger TaskScheduler on Task (after insert, after update) {
    // Iterate through all tasks
    for(Task t : Trigger.new){
        // Schedule follow up task for completed tasks depending on task subject
        if(t.Status == 'Completed'){    
            if(t.Subject == 'Send Initial Email'){
                // update lead status
                Lead myLead = new Lead(Id = t.whoId);
                myLead.Id = t.whoId;
                myLead.Status = 'Working';
                update myLead;
                // schedule new task
                Task newTask = new Task(Subject = 'Make Initial Phone Call', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Make Initial Phone Call'){
                Task newTask = new Task(Subject = 'Send Email #2', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date(), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Send Email #2'){
                Task newTask = new Task(Subject = 'Make Phone Call #2', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Make Phone Call #2'){
                Task newTask = new Task(Subject = 'Send Email #3', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date(), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Send Email #3'){
                Task newTask = new Task(Subject = 'Make Phone Call #3', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            // When final task is completed, change lead status to 'unresponsive'
            } else if(t.Subject == 'Make Phone Call #3'){
                // update lead status
                Lead myLead2 = new Lead(Id = t.whoId);             
                myLead2.Id = t.whoId;     
                myLead2.Status = 'Unresponsive';
                update myLead2;
            }
        }    
    }
}

My test class so far:
@isTest
private class TestTaskScheduler {
    public static testMethod void validateScheduler(){
        // Start Test
        System.Test.startTest();
        Lead myLead = new Lead();
        String userId = UserInfo.getUserId();
        List<Task> taskList = new List<Task>();
        for(integer i = 0; i < 6; i++){
            Task t = new Task();
            t.OwnerId = userId;
            t.Subject = 'Send Initial Email';
            t.priority= 'Normal';
            t.status = 'Completed';
            t.description = 'Testing';
            t.ActivityDate = system.now().Date();
            t.whoId = myLead.Id;
            taskList.add(t);
        }
        taskList[1].Subject = 'Make Initial Phone Call';
        taskList[2].Subject = 'Send Email #2';
        taskList[3].Subject = 'Make Phone Call #2';
        taskList[4].Subject = 'Send Email #3';
        taskList[5].Subject = 'Make Phone Call #3';
        insert taskList;
        System.Test.stopTest(); 
    }
}

Thanks!
External system(SharePoint) is making SOAP API call to create a record in salesforce, on which creation of records upon meeting a field criteria a workflow should be triggered in updating field values. When a record is created through Salesforce UI the workflow runs fine but when it is getting created through API call seems like workflow is not running. 

So is it something like we cannot invoke Workflow/Aprroval process in sfdc through external API call? If so what thinigs should be done to trigger Workflow/approval process through external SOAP API calls?
Hi Guys,

I am trying to upload an components to an unmanaged package but it keeps failing. The reason is I have a couple of triggers that are running in the Production Org that seem to be causing this to fail.

I have added both the trigger and the test class to the unmanaged package but I keep getting a test class error message. 

Any help would be greatly appreciated.
Below is code of the Apex class - 
public class Test2 {
    
    public static void GetEntitlementProcess(){
        
       ReadResult readResult = metadataConnection.readMetadata('EntitlementProcess','PRAS 01');     
        
    }

}

Whenever I save this class I am getting the error "Invalid type: ReadResult". I generated the Metadata WSDL and then generated the Apex class from the "Generate from WSDL" button in Apex Class section in salesforce. But still when I make the metadata call I receive the above error. I even tried referring the ReadResult datatype by using the Apex class generated from WSDL with the dot operator before the name (ClassName.Readresult). But still the error persists. Any solutions ?
I'm receiving the following error on challenge #6 of the Lightning Superbadge:

Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Delete failed. First exception on row 0 with id 0035000002hUBgRAAW; first error: DELETE_FAILED, Your attempt to delete Sam the ninja could not be completed because it is associated with the following adventure packages.: null, null : []

Looking at the Developer Console, it looks like the code which checks the system is forgetting to delete the Adventure Package records before deleting the Contact. Has anyone else run into this issue?

Thank you!
I'm getting the below error on step 6 of the Lightning Experience.  Has anyone else received this?  It's coming from when they are trying to delete their own contact that they created, but can't because of:

Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Delete failed. First exception on row 0 with id 0035000002glBWHAA2; first error: DELETE_FAILED, Your attempt to delete Sam the ninja could not be completed because it is associated with the following adventure packages.: null, null : []
Hi Evertone,
I had recently updated my email id in Trailhead profile & dev org to match my Partner account with salesforce. But when i try to linked the new email id with the account, then it did not reflect all my badges. Also when i tried linking the old email id then the sync was successful with again less no.of badges. Seems the badges are tagged to the email ids. Some are with the old and some with the new. 
Also the salesforce partner community allows you to only add one salesforce trailhead account.

Thanks
Sumedh
Hi,

I was doing my admin beginner trailhead (Topic:Customizing Compact Layouts)  and encountered this error while checking my completed challenge:

Challenge not yet complete... here's what's wrong: 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: HNZSZYUI


Kindly help with this.

Thank You.
 
Hi!

I'm have developed a managed released package. Passed the security review. In the next release, I want to add a force.com site because in package we are providing a form which is supposed to be fetched through a site. Till our latest release we are only adding the page to the package and then configuring the sire after installing the package in customer's Salesforce org. But this is sometimes causing problem, as form submission is not working due to some permission issues in site profile. So instead of configuring the site after package installation, we want to provide a fully configured force.com site in the package. Is this possible?

Thanks in advance!!
Shruti
Hello,

I have created a Quick Text to use in the Case Feed email channel that contains a merge field for a Rich Text Area field on the Case.  When I invoke the Quick Text in the body of the email I'm composing in the Case Feed view, only the plain text is copied from what was merged, even though the Case Feed supports markup.  It appears to be purposely stripping out the HTML tags.

After failing to find an answer using the Google machine, I'm hoping someone here has an idea on how I can get around this limitation.  Ultimately, I want to be able to use Quick Text with a referenced rich text area field merged into the email I'm composing while maintaining the formatting of the merged field.  Any help or thoughts would be sincerely appreciated.

Thanks!
 

Hi,

 

I want to do a multi-part post from Apex to salesforce itself for an image. And salesforce expects binary data for the image. However we need to prefix the header with boundary as part of multipart convention and append footer so that receiving end (salesforce in this case) can parse the same and process the data(Image in this case). The issue is image is a blob and headers and footers are string. And we cannot directly concatenate these 3 parts in Apex to send to SF.

 

One possible way suggested by people who had similar issues was use base64encoded to convert blob to string and concatenate the header and footer. This is good and works but only 33% of times. Reason is base64 encdoing appends "=" or "==" sign to padd at the end if the source blob data bytes are not exact multiple of 3 (This is how base64encoding works). So these padded characters creates issues if they are appended while encoding. There is no fruitful way i am able to figure out to resolve this final issue and I get 400 bad request by SF. There was a way suggested by @Enreeco in his blog but that resolves the error from 400 to a successful 201 return value. But the background issue is that the way the "=" characters were removed actually corrupted the blob data, so receiving end receives a valid request but NOT a valid content and thus image is not really uploaded and assigned to the profile.

 

To avoid the above concatenation problem, I also tried to set Content-Transfer-Encoding as "base64" and sending only the image as base64encoded and header/ footers as normal string, however that request is also generating 500 server error.

Has anyone faced any similar issues or has any pointers for any workaround either for concatenating the header, footer string to blob body or else for resolving the padded "=" characters and not corrupting the data. Or has anybody successfully tried using base64 as Content-Transfer-Encoding method to send multi-part post? Any help is highly appreciated.

 

Thanks in advance

 

Kamal

Hi all,


I am trying to figure out have to track Quick Text feature when a agent uses it. Basically, how many time a quick text was use over a given time, How many times did an Agent use a specific quick text over a period of time, etc..


I have looked into the Quick Text reports and/or "Sample Quick Text Report" but there's no count field or anything, you can report on any of the fields like title, description, category, etc..


So now I am thinking of creating our own count field and then write an apex trigger to update the field each time it's used if possible.


I want to know if there is a better way to work this solution or how to go about adding apex trigger to get the same results.
Any suggestions would be helpful.

 

 

  • July 17, 2013
  • Like
  • 0

Force.com gurus,

 

Are there any plans to support unauthenticated Apex REST?  We really need the ability to have outside systems post data to our customer's Salesforce accounts and those systems don't have the capability to authenticate.  So, we're basically looking for a servlet type listener.


Thanks,
Jon

 

p.s. -- we've looked at using Sites for this, but there's currently no way to access to the HTTP body of the request.



Can someone tell me how to represent a byte array in apex?

Say i have a byte array 

byte[] vk = {1,24,45,26,75};

is there is some way to write this array in salesforce? 

please replay, the answer that solve this will be selected as a best answer. thanks
I am trying to update the status of a lead from a task trigger if a certain task is completed. When testing my code the execution always seems to stop when I try to update the lead. I think this may be because in my test class the tasks are not assigned to a lead, but when I tried creating a sample lead to use I think I made a mistake because the test then gets 0% code coverage.
trigger TaskScheduler on Task (after insert, after update) {
    // Iterate through all tasks
    for(Task t : Trigger.new){
        // Schedule follow up task for completed tasks depending on task subject
        if(t.Status == 'Completed'){    
            if(t.Subject == 'Send Initial Email'){
                // update lead status
                Lead myLead = new Lead(Id = t.whoId);
                myLead.Id = t.whoId;
                myLead.Status = 'Working';
                update myLead;
                // schedule new task
                Task newTask = new Task(Subject = 'Make Initial Phone Call', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Make Initial Phone Call'){
                Task newTask = new Task(Subject = 'Send Email #2', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date(), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Send Email #2'){
                Task newTask = new Task(Subject = 'Make Phone Call #2', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Make Phone Call #2'){
                Task newTask = new Task(Subject = 'Send Email #3', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date(), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            } else if(t.Subject == 'Send Email #3'){
                Task newTask = new Task(Subject = 'Make Phone Call #3', IsReminderSet = True, ReminderDateTime = System.now(), Activitydate = System.now().date().addDays(1), WhoId = t.WhoId, ownerId = t.ownerId);
                insert newTask;
            // When final task is completed, change lead status to 'unresponsive'
            } else if(t.Subject == 'Make Phone Call #3'){
                // update lead status
                Lead myLead2 = new Lead(Id = t.whoId);             
                myLead2.Id = t.whoId;     
                myLead2.Status = 'Unresponsive';
                update myLead2;
            }
        }    
    }
}

My test class so far:
@isTest
private class TestTaskScheduler {
    public static testMethod void validateScheduler(){
        // Start Test
        System.Test.startTest();
        Lead myLead = new Lead();
        String userId = UserInfo.getUserId();
        List<Task> taskList = new List<Task>();
        for(integer i = 0; i < 6; i++){
            Task t = new Task();
            t.OwnerId = userId;
            t.Subject = 'Send Initial Email';
            t.priority= 'Normal';
            t.status = 'Completed';
            t.description = 'Testing';
            t.ActivityDate = system.now().Date();
            t.whoId = myLead.Id;
            taskList.add(t);
        }
        taskList[1].Subject = 'Make Initial Phone Call';
        taskList[2].Subject = 'Send Email #2';
        taskList[3].Subject = 'Make Phone Call #2';
        taskList[4].Subject = 'Send Email #3';
        taskList[5].Subject = 'Make Phone Call #3';
        insert taskList;
        System.Test.stopTest(); 
    }
}

Thanks!
External system(SharePoint) is making SOAP API call to create a record in salesforce, on which creation of records upon meeting a field criteria a workflow should be triggered in updating field values. When a record is created through Salesforce UI the workflow runs fine but when it is getting created through API call seems like workflow is not running. 

So is it something like we cannot invoke Workflow/Aprroval process in sfdc through external API call? If so what thinigs should be done to trigger Workflow/approval process through external SOAP API calls?