Friday 30 October 2015

Brief Steps To Setup "Force.com Continuous Integration"

Continuous Integration may help in following ways:

  • Maintain a code repository
  • Automate the build
  • Make the build self-testing
  • Everyone commits to the baseline every day
  • Every commit (to baseline) should be built
  • Keep the build fast
  • Test in a clone of the production environment,ie., sandbox
  • Make it easy to get the latest deliverables
  • Everyone can see the results of the latest build
  • Automate deployment


Software Requirements


1. ANT
2. Force.com Migration Tool
3. Git
4. Eclipse
5. Jenkins war file

Set up environment variables for Git(/bin), JDK(/bin), ANT(/bin)


ECLIPSE  <------>  BITBUCKET

Step 1: Add the components in your Force.com project

Step 2: Configure Local Repository

Team --> Share Project --> Create --> Local Repo Name and Location --> Finish button --> Question mark '?' on folders (Git doesn't know what to do with files because they are not indexed) --> Add Index to the componenet you wnat to commit --> Cross mark 'x' on folders --> Commit --> Cylinder mark on indexed folders.

Step 3: Create Bitbucket remote repository. Get the repo URL.

In Eclipse, go to GIT perspective --> Get all local repository --> under Remote, Create Remote --> Select Configure Push --> Ok button --> Change button --> Git repo URL --> Username, Password --> Check Store in Secure Store --> Finish button --> On parent window, click Add --> In new window, Local branch and Remote Branch to "refs/heads/master" or "ctrl+space bar" --> Ok --> Dry Run --> Save and Push to move changes from local repository to remote repository.

BITBUCKET  ------>  JENKINS   --------> Target SFDC INSTANCE


Step 1: Go to http://localhost:8080/

Step 2: New Item (Freestyle project)

Sep 3: Manage Jenkins --> Manage Plugins --> Check/Install GitBucket plugin --> Check/Install Chatter Notifier plugin --> Check/Install Release plugin

Step 4: Select your project --> Configure  --> SCM : Git --- Provide Bitbucket repo URL and Credentials --- Specify branch to build (*/master  OR refs/tags/DEV)  --> Build Triggers : Build when a change is pushed to BitBucket  OR  Build periodically  --- Invoke ANT   --> Post-build Actions : Chatter results

Step 5: Set up web hooks in bitbucket

Go back to your Jenkins main page, click on “People” link in the sidebar
In the People page, click on our newly created account’s entry
Click on the “Configure” link in the sidebar
Under “API Token”, click on the “Show API Token” button and copy that token.

Under the repository’s admin page, click on “Services” at the sidebar:
Choose “Jenkins” from the “Select a service…” drop-down and click on “Add Service”.

Endpoint: http://bitbucketusername:apitoken@yourjenkinsurl.com/
Project name: Jenkins project name
Token:Authentication token from Jenkins
Module name(Optional)


For more info, let's collaborate in here.  :)

Tuesday 27 October 2015

Considerations for Approval Process: Field updates don’t evaluate custom validation rules on fields


Requirement
I came across one scenario where the requirement was to prevent an approval process field update action when a Credit/Debit record is in Invoiced status though the record is still in the approval process.

Background
When a Credit/Debit record is submitted for approval process, there may be scenario where the approver may be on leave or may delay in approving that request. In the meantime, SAP, an external integrated system, can make an update on this record by invoicing the data even without any approval notification from Salesforce.com to SAP.

Actions taken
I thought of keeping a validation rule to prevent the approver from making any change if the record is invoiced from SAP.
However this didn't happen because of this simple fact below.

Facts
One of the considerations for Approval Process is "Field updates don’t evaluate custom validation rules on fields". So in this case, a custom validation rule won’t fire inside an approval process.

To be continued..
The search for some other workaround is ON..  

Friday 16 October 2015

Scheduling Batch Job To Run Every N-Minutes in Salesforce.com


Have you ever wondered or come across scheduling batch job to run every N-Minutes( for example 1 minute or 5 minutes)?
Yes, I have! Since this is not possible to do thru standard Salesforce UI.

Sometimes  in order to do so, we go for scheduling multiple times; for example 11 times if it has to be scheduled every 5 minutes. Here is the next question: Can't it be done in a single scheduling attempt? Yes, it can be. The next is the solution..  


So here is a small code to do so for every 5 minutes. You can customize your logic for every N_minutes. You can execute this piece of code in developer console as well.

DateTime myDateTime = System.Now() ;
System.debug('Sudhir myDateTime:: ' + myDateTime) ;


static Integer iHour = myDateTime.hour() ;

System.debug('Sudhir iHour :: ' + iHour) ;

static Integer iMinute = myDateTime.minute() ;
System.debug('Sudhir iMinute:: ' + iMinute) ;

static Integer iSecond = myDateTime.second() ;
System.debug('Sudhir iSecond:: ' + iSecond) ;

for(Integer i = 0; i < 60 ; i = i + N){ 
    if(iSecond > 59){
        iSecond = 0 ;
    }  
  if(iMinute > 55){
        iMinute = 0 ;
        iHour = iHour + 1 ;
    } else{
        iMinute = iMinute + N ;
    }
    String sExpression = String.valueOf(iSecond) + ' ' + String.valueOf(iMinute) + ' ' + '*' +  ' ' + '*' + ' ' + '*' + ' ' + '?' + ' ' + '*' ;
    System.debug('Sudhir sExpression:: ' + sExpression) ;

     ScheduledBatchJob_APIName oScheduledBatchJob_APIName = new ScheduledBatchJob_APIName () ;
     System.schedule('Comment for Scheduled batch Job' + '-' + i, xpression, oScheduledBatchJob_APIName) ;
}








Happy Apex coding and sharing..