Browse Month: May 2013

Get related list without Action Column in visualforce page

Hi,

When you want to display related list on visualforce page, you can use <apex:relatedList>
tag, and it is very easy for ex:

<apex:page standardController="MyMasterObject__c">
	<apex:relatedList list="MyChildObjects__r" />
</apex:page>

but this will display all the columns from related list including “Action” column and many times
we don’t want to display this column.

so to access your related list in the visualforce page without adding columns such as “Action“;
for example to access your products from Opportunity Page then use <apex:repeat> or <apex:dataTable>
tags from visualforce. for example here is a code to access your Estimate products which is related list
on Estimate page from visualforce page:

<apex:dataTable value="{!Estimate__c.EstimateOrder__r}" var="eorl">
<apex:column headerValue="Product" width="10%">
<apex:outputText value="{!eorl.Product_Code__c}"></apex:outputText>
</apex:column>
<apex:column headerValue="Width" width="10%">
<apex:outputText value="{!eorl.Width__c}"></apex:outputText> </apex:column>
<apex:column headerValue="Height" width="10%">
<apex:outputText value="{!eorl.Height__c}"></apex:outputText> </apex:column>
</apex:dataTable>

This above code will display all your related list values on visualforce page without any column such as “Action
in a list.
To use <apex:repeat> replace <apex:dataTable> with <apex:repeat> and other fields are same.

Hope this will helpful for you.

Thanx.

 

 

Custom Send Email button on custom Objects

Hi,

If you want to add a custom button to send email on custom object then follow below mentioned

steps:

1. Create Custom button on custom object;

2. in the content source, select URL;

3. in the value section, add following url

https://na15.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid={!Estimate__c.Bill_To_NameId__c}&rtype=003&doc_id=00Pi0000000OluX&retURL=/{!Estimate__c.Id}?srPos=0&srKp=00T

where Estimate__c.BillToNameId__c is the contact Id to whom you want to send email

and

Estimate__c.Id is the return URL of your custom object

Thanks.

java.lang.OutOfMemoryError: Java heap space

add line to catalina.sh or catalina.bat:

export CATALINA_OPTS=”-Xms512M -Xmx1024M”

a) The -Xmx argument defines the max memory size that the heap can reach for the JVM. A low value can cause OutOfMemoryExceptions or a very poor performance if your program’s heap memory is reaching the maximum heap size.
b) The -Xms argument sets the initial heap memory size for the JVM. This means that when you start your program the JVM will allocate this amount of memory instantly.

java.security.AccessControlException: access denied (java.net.SocketPermission host connect,resolve)

The Simple solution is
:search catalina.policy file and edit green line as

// Precompiled JSPs need access to this system property.
permission java.util.PropertyPermission”org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER”,”read”;

permission java.net.SocketPermission “*”, “connect”;
permission java.net.SocketPermission “*”, “connect”;
permission java.net.SocketPermission “*”, “connect”;

permission java.lang.RuntimePermission “accessDeclaredMembers”;
permission java.lang.RuntimePermission “accessClassInPackage.org.apache.jasper.el”;
permission java.lang.RuntimePermission “stopThread”;
permission java.lang.RuntimePermission “modifyThread”;
permission java.lang.RuntimePermission “modifyThreadGroup”;

The possible ways to connect to the host are
a)accept
b)connect
c)listen
d)resolve

The “listen” action is only meaningful when used with “localhost”. The “resolve” action is implied when any of the other actions are present. The action “resolve” refers to host/ip name service lookups.

You can also put your Host_Address instead *.
* will allow to you connect any hostAddress as well localhost
more info : http://docs.oracle.com/javase/1.4.2/docs/api/java/net/SocketPermission.html

Learning The Many Advantages of PHP

PHP, which is short for Hypertext Preprocessor, is an open source server side programming language available at free of cost that can be easily obtained from the market. It has a coding style that is quiet and easy to understand and is usually very proficient on multi-platforms like Windows, Linux, and UNIX and other more.

Today, PHP is one of the most popular server side scripting languages working. It is basically utilized for making dynamic web pages that correspond with the user offering customized information. Aside from being fast, stable, secure and easy to use, PHP offers other numerous advantages that had most developers using it.

Before even starting any website, several aspects are considered including:

  • Website design
  • Web developing
  • Web hosting
  • Maintenance
  • Flexibility
  • Usability
  • Scalability
  • Easiness of handling and
  • Overall allocated budget

Advantages of PHP

PHP is an open source

As previously mentioned, PHP is readily available and totally free for you to use. If you have been planning to hire PHP developers who have excellent background in C and Java, you will notice how easy it is for them to use PHP. And truth be told, PHP is a lot simpler compared to the rest giving you assurance of outstanding outcomes. The chief PHP source repository is rich with modules and interfaces that users have written and donated. With that source, you can gladly search for modules for flash movies, PDF files, calendars and other more.

PHP is cross-platform.

  • PHP runs on just about every platform available enabling it to operate across different operating systems. It works excellently on UNIX, Macs and Windows versions.

PHP has connective abilities.

  • It uses a modular system of extensions to cross point with a collection of libraries like graphics, XML, encryption and other more. Furthermore, programmers can stretch out PHP by writing their own extensions and gathering them into the executable or they can make their own executable and load it with the use of PHP’s dynamic loading mechanism.

PHP offers a community.

  • You can easily share with other people in the PHP community since it is an open source project. If you are searching for a specific script, chances are another user has already made something similar. You can simply check within the PHP community for availability. In the same way, if you have made a function that others can benefit, be sure to post the code for others.
  • The PHP community is a huge one. Because of its popularity, there are many PHP developers, contributors, users and employers that gladly offer PHP jobs. You can easily find people who are looking for a PHP developer job.

PHP is fast and convenient.

  • It functions well with other software available and is known to be fast. PHP is also relatively stable. And because it is an open source, anyone on the PHP community can fix the bug.
  • When it comes to security, PHP offers several levels of security to avert malicious attacks.
  • PHP does not put exertion on servers because it utilizes its own inherent memory space that reduces the workload from the servers. The processing speed impulsively improves. Its script is also improved enabling the server’s job a lot easier.
  • Data handling in PHP is convenient because the programmers can simply store data, serialize, create cookies, calculate viewer by cookies and sessions and has exceptional file management system.
  • Because PHP is very fast to develop, it assures that there is consequently a quick turnaround time. When you employ PHP developers, their efficacy brings you an online answer that you were most likely searching for since a long time.

PHP is pre-configured

  • More often, hosting services have a “ready to use” PHP setup. With this, it will not require any distinctive configuration. But you can always modify if you wish to put up a high security kind of website.

 

Display Facebook likes / Shares PHP function

The Code
Below is a super simple function that retrieves a JSON feed of comments, likes and shares for any URL you provide.

function facebook_shares($url){

$fql = “SELECT url, normalized_url, share_count, like_count, comment_count, “;
$fql .= “total_count, commentsbox_count, comments_fbid, click_count FROM “;
$fql .= “link_stat WHERE url = ‘”.$url.”‘”;

$apifql=”https://api.facebook.com/method/fql.query?format=json&query=”.urlencode($fql);
$fb_json=file_get_contents($apifql);
return json_decode($fb_json);

}

How to use

$fb = facebook_shares(‘https://www.facebook.com/redbull’);

// facebook share count
echo $fb[0]->share_count;

// facebook like count
echo $fb[0]->like_count;

// facebook comment count
echo $fb[0]->comment_count;

Show Google Plus’s – PHP function

It’s worth pointing out you must have CURL enabled on your web server, I believe it’s enabled by default on PHP5 setups. Also the Key below Isn’t a unique API key you must leave the key as is to ensure the code works properly.

function gplus_shares($url){

// G+ DATA
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, ‘[{“method”:”pos.plusones.get”,”id”:”p”,
“params”:{“nolog”:true,”id”:”‘ . $url . ‘”,”source”:”widget”,”userId”:”@viewer”,”groupId”:”@self”},
“jsonrpc”:”2.0″,”key”:”p”,”apiVersion”:”v1″}]’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-type: application/json’));

$result = curl_exec ($ch);
curl_close ($ch);
return json_decode($result, true);

}

Example Usage

$gplus = gplus_shares(‘https://facebook.com’);

echo $gplus[0][‘result’][‘metadata’][‘globalCounts’][‘count’];

Voice Recording in Android

Put below code into your main Activity.

private static final String AUDIO_RECORDER_FILE_EXT_3GP = ".3gp";
private static final String AUDIO_RECORDER_FILE_EXT_MP4 = ".mp4";
private static final String AUDIO_RECORDER_FOLDER = "AudioRecorder";
private MediaRecorder recorder = null;
private int currentFormat = 0;
private int output_formats[] = { MediaRecorder.OutputFormat.MPEG_4, MediaRecorder.OutputFormat.THREE_GPP };
private String file_exts[] = { AUDIO_RECORDER_FILE_EXT_MP4, AUDIO_RECORDER_FILE_EXT_3GP };

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setButtonHandlers();
enableButtons(false);
setFormatButtonCaption();
}

private void setButtonHandlers() {
((Button) findViewById(R.id.btnStart)).setOnClickListener(btnClick);
((Button) findViewById(R.id.btnStop)).setOnClickListener(btnClick);
((Button) findViewById(R.id.btnFormat)).setOnClickListener(btnClick);
}

private void enableButton(int id, boolean isEnable) {
((Button) findViewById(id)).setEnabled(isEnable);
}

private void enableButtons(boolean isRecording) {
enableButton(R.id.btnStart, !isRecording);
enableButton(R.id.btnFormat, !isRecording);
enableButton(R.id.btnStop, isRecording);
}

private void setFormatButtonCaption() {
((Button) findViewById(R.id.btnFormat)).setText(getString(R.string.audio_format) + " (" + file_exts[currentFormat] + ")");
}

private String getFilename() {
String filepath = Environment.getExternalStorageDirectory().getPath();
File file = new File(filepath, AUDIO_RECORDER_FOLDER);
if (!file.exists()) {
file.mkdirs();
}
return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]);
}

private void startRecording() {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(output_formats[currentFormat]);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

private void stopRecording() {
if (null != recorder) {
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}
}

private void displayFormatDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
String formats[] = { "MPEG 4", "3GPP" };
builder.setTitle(getString(R.string.choose_format_title)).setSingleChoiceItems(formats, currentFormat, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
currentFormat = which;
setFormatButtonCaption();
dialog.dismiss();
}
}).show();
}

private MediaRecorder.OnErrorListener errorListener = new MediaRecorder.OnErrorListener() {
@Override
public void onError(MediaRecorder mr, int what, int extra) {
Toast.makeText(AudioRecordingActivity.this, "Error: " + what + ", " + extra, Toast.LENGTH_SHORT).show();
}
};

private MediaRecorder.OnInfoListener infoListener = new MediaRecorder.OnInfoListener() {
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
Toast.makeText(AudioRecordingActivity.this, "Warning: " + what + ", " + extra, Toast.LENGTH_SHORT).show();
}
};

private View.OnClickListener btnClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnStart: {
Toast.makeText(AudioRecordingActivity.this, "Start Recording", Toast.LENGTH_SHORT).show();
enableButtons(true);
startRecording();
break;
}
case R.id.btnStop: {
Toast.makeText(AudioRecordingActivity.this, "Stop Recording", Toast.LENGTH_SHORT).show();
enableButtons(false);
stopRecording();
break;
}
case R.id.btnFormat: {
displayFormatDialog();
break;
}
}
}
};

How to Add Smiley/Emojis in Edittext?

 

Emoji.java :-

package com.android.emoji;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Emoji extends Activity implements OnClickListener {
EditText edttxtemoji;
Button btnsubmit, btnselectemoji;
TextView txtviewdisplay;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edttxtemoji = (EditText) findViewById(R.id.edttxtemoji);
btnsubmit = (Button) findViewById(R.id.btnok);
btnsubmit.setOnClickListener(this);
btnselectemoji = (Button) findViewById(R.id.btnselect);
btnselectemoji.setOnClickListener(this);
txtviewdisplay = (TextView) findViewById(R.id.txtviewdisplay);
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == btnsubmit) {
txtviewdisplay.setText(edttxtemoji.getText());
} else if (v == btnselectemoji) {
Intent in = new Intent(this, Select_Emoji_Activity.class);
startActivity(in);
}
}

CharSequence cs;
Custom_List_Emoji cstlistemoji;
int index;

@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();

cstlistemoji = new Custom_List_Emoji(this);
@SuppressWarnings("static-access")
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs",
this.MODE_WORLD_READABLE);
index = myPrefs.getInt("key1", 0);
System.out.println("Pref Data index is:- " + index);
ImageGetter imageGetter = new ImageGetter() {
public Drawable getDrawable(String source) {
Drawable d = getResources().getDrawable(
cstlistemoji.images[index]);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
cs = Html.fromHtml(
"", imageGetter, null);
System.out.println("cs is:- " + cs);
edttxtemoji.setText(cs);
}
}

Select_Emoji_Activity.java :-

package com.android.emoji;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class Select_Emoji_Activity extends Activity implements OnItemClickListener{
ListView lstviewemojis;
Custom_List_Emoji cstlistemoji;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.emojis);
lstviewemojis=(ListView)findViewById(R.id.lstviewemojis);
lstviewemojis.setOnItemClickListener(this);
cstlistemoji=new Custom_List_Emoji(this);
lstviewemojis.setAdapter(cstlistemoji);
}
@Override
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
System.out.println("Emoji is:- " +arg2);
prefsEditor.putInt("key1", arg2);
prefsEditor.commit();
finish();
}
}

Custom_List_Emoji :-

package com.android.emoji;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Custom_List_Emoji extends BaseAdapter {

public Activity context;
public LayoutInflater inflater;

public Custom_List_Emoji(Activity context) {
// TODO Auto-generated constructor stub
this.context = context;
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return emojis.length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
String temp = emojis[position];
return temp;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}

TextView txtview1;
ImageView image;

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = inflater.inflate(R.layout.custom_emojis, null);
txtview1 = (TextView) convertView.findViewById(R.id.txtviewemojis);
image = (ImageView) convertView.findViewById(R.id.imgviewemoji);
}

image.setImageResource(images[position]);
txtview1.setText(emojis[position]);
return convertView;
}

 

public final int[] images = new int[] { R.drawable.emo_im_happy,
R.drawable.emo_im_sad, R.drawable.emo_im_winking,
R.drawable.emo_im_tongue_sticking_out, R.drawable.emo_im_surprised,
R.drawable.emo_im_kissing, R.drawable.emo_im_yelling,
R.drawable.emo_im_cool, R.drawable.emo_im_money_mouth,
R.drawable.emo_im_foot_in_mouth, R.drawable.emo_im_embarrassed,
R.drawable.emo_im_angel, R.drawable.emo_im_undecided,
R.drawable.emo_im_crying, R.drawable.emo_im_lips_are_sealed,
R.drawable.emo_im_laughing, R.drawable.emo_im_wtf };
public final String[] _strEmoticonLabels = new String[] { "Happy", "Sad",
"Winking", "Tongue sticking out", "Surprised", "Kissing",
"Yelling", "Cool", "Money Mouth", "Foot in mouth", "Embarrased",
"Angel", "Undecided", "Crying", "Lips are sealed", "Laughing",
"Confused" };
public final String[] emojis = new String[] { ":-)", ":-(", ";-)", ":-P",
"=-O", ":-*", ":O", "B-)", ":-$", ":-!", ":-[", "O:-)", ":-\",
":'(", ":-X", ":-D", "o_O" };

Draw flexible lines on touches Moved in iphone View Based application

// .h ———File
CGPoint lastPoint;
UIImageView *drawImage;
BOOL mouseSwiped;
int mouseMoved;

//.m ———File
– (void)viewDidLoad
{
[super viewDidLoad];

drawImage = [[UIImageView alloc] initWithImage:nil];
drawImage.frame = self.view.frame;
[self.view addSubview:drawImage];
self.view.backgroundColor = [UIColor yellowColor];
}

– (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2)
{
drawImage.image = nil;
return;
}

lastPoint = [touch locationInView:self.view];
lastPoint.y -= 20;
}

– (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 20;

UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

lastPoint = currentPoint;
}