Batch scheduler class testing

Template for batch & scheduler class test method:@isTest

private class Test_Nameofurclass {
    static testmethod void test_Nameofurclass (){
        DateTime currTime = DateTime.now();
        Integer min = currTime.minute();
        Integer hour = currTime.hour();
        String sch;
    if(min <= 58)
            sch = ‘0 ‘+ (min + 1) + ‘ ‘ + hour + ‘ * * ? ‘+ currTime.year();
        else
            sch = ‘0 0 ‘+ (hour + 1) + ‘ * * ? ‘+ currTime.year();
        Test.startTest();
    nameofschedularclass obj = new nameofschedularclass  ();
    String jobId = system.schedule(‘test’, sch, obj);
        CronTrigger ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger where id = :jobId];
        System.assertEquals(sch, ct.CronExpression);
        insert test records satisfying your query.
        database.executeBatch(new nameofurbatchclass());
        Test.stopTest();
    }
}

Salesforce and WSSE security headers

I wanted to name this post as WSSE security header or How i lost my war with the webservice team much like this movie (If you have not watched this i would strongly recommend to watch it).

The requirement looked pretty straight forward consume wsdl , send the request and handle the response. But we faced the issue of WSSE headers. It looks something like this


 

user@email.com *********
The WSDL did not have the header part . So while sending request the above header was not present. The first approach we took was if it was possible for webservice team to support httpheaders instead of soap header. It was denied immediately.

The next step was to code the header into the generated apex class. It is bit tricky and involves extensive understanding of  WSDL2APEX functionality

Modal dialog in VisualForce page using Jquery

{!$Label.GW_Volunteers__labelReturnToCalendar}

 


 

  null}" >

{!$ObjectType.Contact.Fields.Volunteer_Skills__c.Label}:

 
  null}" >

,


 

 

  var x = JobShiftDateTimeString('{!shift.Start_Date_Time__c}', '{!shift.Duration__c}'); 
 OpenSignUpDlg('{!job.Id}', '{!shift.Id}', '{!JSENCODE(job.Name)}', x); 
 return false;"
 >{!$Label.labelLinkSignUp}

 


 

 {!$Label.GW_Volunteers__labelReturnToCalendar}

styleClass=”{!IF(f.Type == ‘Long Text Area’, ‘cssInputFields cssTextArea’, ‘cssInputFields’)}” />

styleClass=”{!IF(f.Type == ‘Long Text Area’, ‘cssInputFields cssTextArea’, ‘cssInputFields’)}” />


immediate=”false” status=”statusSignUp” />



{!$Label.labelVolunteerSignupThankYou}

How to create RowID in Tables : Here is the Code or Script Code for ID creation

If you are looking for to How to create RowID in Tables : Here is the Code or Script Code for ID creation,
Find below a simple Script or Code for generating Row ID or Record ID in Tables for Salesforce
public void viewTracking(){
if(trackingRow != null){
list rowId = trackingRow.split(‘:’);
if(rowId.size() >1){
//system.debug(‘***’+ integer.valueof(rowId[(rowId.size()-2)]));
Tracking =orderDetails[integer.valueof(rowId[(rowId.size()-2)])].Tracking;
}
}
}
Using RowID can be helpful in many ways to identify a record, count the records, classify, add, insert or delete a record or row just with a command in Tables.

SFDC API 24.0 test failure issue

Yesterday I was experiencing a weird issue. My SFDC API Test Failed.For a new requirement we did development in our DEV environment…We wrote new test methods and we thought the work is done :)…
However, there were Null Pointer Exceptionswhen we ran the test methods.
And it was pointing to the custom settings….we doubled checked and confirmed that the custom setting had the default values. Also, it was accessible to anyone (public).After some time I realized that the test method API version was 24.0.. I changed it to 23.0 and there were no errors 🙂

Edit – SFDC has introduced test classes not to access data directly with API 24. Even though it is a good move , I would like to access certain info by default like custom settings, and Pricebook. But there is always an option to use @istest(seealldata=true) to access live data.

http://boards.developerforce.com/t5/General-Development/Custom-setting-not-accessible-from-test-class/m-p/399669#M66636

How to Identify SobjectType Dynamically in Apex

Here is a script that answers your How to Identify SobjectType Dynamically in Apex

getKeyPrefix of Schema.getGlobalDescribe can be used to identify dynamically the SobjectType in Apex.

String prefix = recordId.substring(0,3);
String objectType;
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
for(Schema.SObjectType s : gd.values()){
if(prefix == s.getDescribe().getKeyPrefix()){
objectType = s.getDescribe().Name;
}
}

recordId consists the Id of the sobject Record for whose SobjectType needs to be identified. Above piece of code does it well.

Cool links for SFDC Salesforce.com Tools and Best practices

I was going through the Best practices for force.com and Trigger template. It will be really helpful if we could follow it in our code.You can also find lots of interesting tools for salesforce.com here.

Found this awesome IDE and data loader on the cloud !!! – Workbench . I would have loved to have metadata export on this. If anyone knows a tool not an app through which we can export metadata (not like an XML) more like a spreadsheet which can be used for documentation and data mapping please drop a comment here.

Finally Vote for all the ideas in this link. These are all the features worth having in SFDC.

There are many a times where we need to mimic a standard page through VF. Creating them to mimic it is a hard thing. But it can be done with a single click , whole code gets generated.

You can check that out here. Pretty cool stuff aint it for SFDC Admins SFDC Developers.