Salesforce | Some Date functions (String to Date and more)

| By Webner

We can convert a string variable into date datatype by using the apex date class function date.parse(String); Syntax: Date var1=date.parse(String); Example: String var=’12/25/2016’; Convert var to date type by: Date var1=date.parse(var); Now var1 contain it as a date type. It

Selenium | How to test popup alert message in Selenium Webdriver

| By Webner

Below is the script: package mypackage; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class myclass { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); String alertMessage = “”; driver.get(“http://demo.webnerserver.com/view/sent_email.php”) driver.findElement(By.cssSelector(“input[value=”Borrar”]”)).click(); alertMessage = driver.switchTo().alert().getText(); driver.switchTo().alert().accept(); System.out.println(alertMessage); driver.quit(); }

Salesforce | Calculate number of years between two dates in apex class

| By Webner

Sample Code: Date date1 = System.today(); Date date2 = System.today().addMonths(30); system.debug(‘No of months === >>>> ‘ + date1.monthsBetween(date2)); String noOfYears = String.valueOf(date1.monthsBetween(date2) / 12) + ‘ Year(s) ‘ + String.valueOf(Math.mod(date1.monthsBetween(date2), 12)) + ‘ Month(s)’; system.debug(‘No of years ‘ + noOfYears);

Salesforce | Visualforce | Error : DML currently not allowed exception on creation of the record on an Object

| By Webner

When creating a record on the document object using Rest API, Salesforce did not allow to execute the DML command from the Visualforce component. Reason: When we try to pass dynamic values from the Visualforce Component to the Apex method,

Javascript | Unable to get content of HTML while converting HTML page to PDF

| By Webner

Problem : Unable to get content of HTML while converting HTML page to PDF. Solution : You can use the javascript if you want to get content of HTML while converting it into PDF : <HTML> <head> <script type=”text/javascript”> function submitForPDF() {