Saturday, 17 October 2015

Java awt Package Choice Example

 import java.awt.*; 
public class ChoiceDemo
{
public static void main(String args[])
{
Frame f = new Frame();
f.setLayout(new FlowLayout());
Choice ch = new Choice();
ch.add("India");
ch.add("Nepal");
ch.add("Shri Lanka");
ch.add("USA");
ch.add("UK");
f.add(ch);
f.setSize(300,300);
f.setVisible(true);
}
}

Java awt Package Checkbox Example

	import java.awt.*;
public class CheckboxDemo
{
public static void main(String args[])
{
Frame f = new Frame();
f.setLayout(new FlowLayout());
Checkbox cb = new Checkbox("Literate");
f.add(cb);
f.setSize(300,300);
f.setVisible(true);
}
}

Java awt Package Canvas Example

	import java.awt.* ;
public class CanvasDemo
{
public static void main(String args[])
{
Frame f = new Frame() ;
f.setLayout(new FlowLayout());
MyCanvas c = new MyCanvas();
c.setBackground(Color.red);
c.setSize(100,100);
f.add(c) ;
f.setSize(300,300);
f.setVisible(true);
}
}

class MyCanvas extends Canvas
{
public void paint(Graphics g)
{
setBackground(Color.green) ;
g.setColor(Color.red) ;
g.drawLine(0,0,100,100);
}
}

Java awt Package Button Demo


	import java.awt.*;
class ButtonDemo
{
public static void main(String args[])
{
Frame f = new Frame();
f.setLayout(new FlowLayout());
Button b = new Button("Apply");
f.add(b);
f.setSize(300,300);
f.setVisible(true);
}
}

Wednesday, 14 October 2015

Apex Trigger Salesforce

Apex Trigger is an action which gets fired on particular event. In salesforce trigger is apex code that executes before or after the below types of operations.

– Insert

– Update

– Delete

– Undelete

Triggers will run before object records are inserted, updated, deleted into the database or after records are inserted, updated, deleted and restored.

Apex Triggers can be classified into two types:

1. Before triggers can be used to update or validate record values before they are saved to the database.

2. After triggers can be used to access field values that are set by the database, and to affect changes in other records.

Events in triggers:

Before Insert, Before Update, Before Delete

After Insert, After Update, After delete, After Undelete

Syntax to create sample trigger:

Use below syntax to create trigger.

	trigger <TriggerName> on ObjectName (<events>) {
		// you can write your code here.
	}

Now i will give simple example to under stand how trigger works.

Here i will give example, when account is inserted, automatically contact also created for that account. this example is to under stand how trigger works.

	trigger insertContact on Account (after insert)
	{
		Contact cont = new Contact();
		cont.LastName = Trigger.new[0].name;
		cont.AccountId = Trigger.new[0].ID;
		insert cont;
	}

Above one is a simple trigger to insert contact when you create account. the text which is mentioned in green color is trigger name. And text which is mentioned in red color is event name.

Trigger.New is a context variable. which returns a list of new records of the sobjects which we are going to insert into the database.

Here in salesforce there many context variable available. Those are Trigger.New, Trigger.old, Trigger.NewMap, Trigger.OldMap, Trigger.isAfter, Trigger.isBefore, Trigger.isInsert, Trigger.isUpdate, Trigger.isDelete and Trigger.isUndelete.

We will discuss about each and every context variable later.

Here one more thing i will tell. If you want to move your trigger to Production, you should cover at least 1% code coverage for trigger.

Sunday, 11 October 2015

Java awt Package Border Layout Example 3

	import java.awt.*;
	public class BorderLayout3
	{
		public static void main(String args[])
		{
			Frame f = new Frame();
			f.setLayout(new BorderLayout());
			Panel toolbar = new Panel();
			toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
			toolbar.setBackground(Color.lightGray);
			toolbar.add(new Button("File"));
			toolbar.add(new Button("Edit"));
			toolbar.add(new Button("Tool"));
			toolbar.add(new Button("Help"));
			f.add(toolbar, BorderLayout.NORTH);
			TextField status = new TextField("Status.");
			status.setFont(new Font("Monospaced", Font.BOLD, 48));
			f.add(status, BorderLayout.SOUTH);
			f.add(status, BorderLayout.SOUTH);
			f.setSize(300,300);
			f.setVisible(true);
		}
	}

Java awt Package Border Layout Example 1


	import java.awt.*;
	public class BorderLayout1
	{
		public static void main(String args[])
		{
			Frame f = new Frame();
			Label labelTop = new Label("This is North");
			labelTop.setFont(new Font("Serif", Font.ITALIC, 36));
			labelTop.setForeground(Color.white);
			labelTop.setBackground(Color.black);
			f.add(labelTop, BorderLayout.NORTH);
			Label labelBottom = new Label("This is South");
			labelBottom.setFont(new Font("Monospaced", Font.BOLD, 18));
			labelBottom.setForeground(Color.white);
			labelBottom.setBackground(Color.black);
			f.add(labelBottom, BorderLayout.SOUTH);
			f.setSize(300,300);
			f.setVisible(true);
		}
	}

Java awt Package Border Layout Example 2

	import java.awt.*;
public class BorderLayout2
{
public static void main(String args[])
{
Frame f = new Frame();
Button north = new Button("N");
f.add(north,BorderLayout.NORTH);
f.add(new Button("S"),BorderLayout.SOUTH);
f.add(new Button("E"),BorderLayout.EAST);
f.add(new Button("W"),BorderLayout.WEST);
Panel p = new Panel();
p.setBackground(Color.green);
//f.add(p, BorderLayout.CENTER);
f.add(p); //default is center
f.setSize(300,300);
f.setVisible(true);
}
}