GAME CAPTURE:
Download and install on your system enjoy the game capture features ....
Camtasia Version 7
Friday, June 29, 2012
Monday, June 25, 2012
SENDING MASS EMAIL:
SENDING MASS EMAIL:
One of the useful admin functionality of salesforce sending mass emails and track the status.
Go to Send Mass Email
The following video shows very clear idea on salesforce functionality.
One of the useful admin functionality of salesforce sending mass emails and track the status.
Go to Send Mass Email
The following video shows very clear idea on salesforce functionality.
Sunday, June 24, 2012
POP-UP EXAMPLE:
POP-UP EXAMPLE:
This example shows how to make a pop up on certain action and hide it,it is good example since many of insurance application implementations it is a common req.
Controller:
public class tstpopup {
public boolean displayPopup {get; set;}
public void closePopup() {
displayPopup = false;
}
public void showPopup() {
displayPopup = true;
}
}
Visualforce Page:
<apex:page controller="tstpopup">
<apex:form >
<apex:commandButton value="Show Pop up" action="{!showPopup}" rerender="tstpopup"/>
<apex:pageBlock >
This is just filler text from the Salesforce General.
</apex:pageBlock>
<apex:outputPanel id="tstpopup">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
This is where I would put whatever information I needed to show to my end user.<br/><br/><br/>
<apex:commandButton value="Hide Pop up" action="{!closePopup}" rerender="tstpopup"/>
</apex:outputPanel>
</apex:outputPanel>
</apex:form>
<style type="text/css">
.custPopup{
background-color: white;
border-width: 2px;
border-style: solid;
z-index: 9999;
left: 50%;
padding:10px;
position: absolute;
/* These are the 3 css properties you will need to change so the popup
displays in the center of the screen. First set the width. Then set
margin-left to negative half of what the width is. You can add
the height property for a fixed size pop up if you want.*/
width: 500px;
margin-left: -250px;
top:100px;
}
.popupBackground{
background-color:black;
opacity: 0.20;
filter: alpha(opacity = 20);
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 9998;
}
</style>
</apex:page>
This example shows how to make a pop up on certain action and hide it,it is good example since many of insurance application implementations it is a common req.
Controller:
public class tstpopup {
public boolean displayPopup {get; set;}
public void closePopup() {
displayPopup = false;
}
public void showPopup() {
displayPopup = true;
}
}
Visualforce Page:
<apex:page controller="tstpopup">
<apex:form >
<apex:commandButton value="Show Pop up" action="{!showPopup}" rerender="tstpopup"/>
<apex:pageBlock >
This is just filler text from the Salesforce General.
</apex:pageBlock>
<apex:outputPanel id="tstpopup">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
This is where I would put whatever information I needed to show to my end user.<br/><br/><br/>
<apex:commandButton value="Hide Pop up" action="{!closePopup}" rerender="tstpopup"/>
</apex:outputPanel>
</apex:outputPanel>
</apex:form>
<style type="text/css">
.custPopup{
background-color: white;
border-width: 2px;
border-style: solid;
z-index: 9999;
left: 50%;
padding:10px;
position: absolute;
/* These are the 3 css properties you will need to change so the popup
displays in the center of the screen. First set the width. Then set
margin-left to negative half of what the width is. You can add
the height property for a fixed size pop up if you want.*/
width: 500px;
margin-left: -250px;
top:100px;
}
.popupBackground{
background-color:black;
opacity: 0.20;
filter: alpha(opacity = 20);
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 9998;
}
</style>
</apex:page>

Saturday, June 23, 2012
PLAY GAME IN SALESFORCE:
PLAY GAME IN SALESFORCE:
This is a simple example of how the flash works in salesforce.The code looks like this
Visualforce Page:
<apex:page sidebar="false" >
<apex:flash src="{!$Resource.movie6}" height="400" width="1500" play="true"></apex:flash>
</apex:page>
Download your static resource from Movie6
This is a simple example of how the flash works in salesforce.The code looks like this
Visualforce Page:
<apex:page sidebar="false" >
<apex:flash src="{!$Resource.movie6}" height="400" width="1500" play="true"></apex:flash>
</apex:page>
Download your static resource from Movie6
Friday, June 15, 2012
PANELGROUP & PANELGRID:
PANELGROUP & PANELGRID:
If you want to customize your data location in your forms Panelgroup & Panelgrid is one of the most usage tags.You can find recruiting application sign up as i mentioned in my previous post
http://bejawadabalayya.blogspot.com/2012/06/working-with-webservices-there-are-two.html
Visualforce page:
<apex:page standardController="Candidate__c">
<style type="text/css">
table.topTable{
border: 1px solid #d95d2e;
}
table.topTable td.photoCol{
text-align: right;
vertical-align: middle;
}
table.topTable td.fieldsCol{
text-align: left;
vertical-align: middle;
}
table.photo{
text-align: center;
vertical-align: middle;
}
table.data{
vertical-align: middle;
}
table.data td.label{
text-align: right;
font-weight: bold;
font-size: 1.5em;
}
table.data td.data{
text-align: left;
font-size: 1.5em;
}
h1.photo {
font-size: 2em;
}
</style>
<apex:insert name="header"/>
<!-- After the header show the photo and top level data -->
<apex:panelGrid columns="2" id="topTable" width="100%" border="1"
frame="box" rules="none"
styleClass="topTable" columnClasses="photoCol,fieldsCol"
cellpadding="5" cellspacing="5">
<!-- Picture Column -->
<apex:panelGrid columns="1" id="pictureGrid" styleClass="photo" width="100%"
cellpadding="10" cellspacing="10">
<apex:image url="{!Candidate__c.Picture_URL__c}"/>
<apex:outputText >
<hr width="80%"/>
<h1 class="photo">{!Candidate__c.First_Name__c} {!Candidate__c.Last_Name__c}</h1>
</apex:outputText>
</apex:panelGrid>
<apex:panelGrid columns="1" id="dataGrid" >
<apex:panelGroup >
<apex:panelGrid columns="2" styleClass="data" columnClasses="label,data">
<apex:outputLabel value="Phone:" />
<apex:outputField value="{!Candidate__c.Phone__c}"/>
<apex:outputLabel value="Mobile:"/>
<apex:outputField value="{!Candidate__c.Mobile__c}"/>
<apex:outputLabel value="Fax:"/>
<apex:outputField value="{!Candidate__c.Fax__c}"/>
<apex:outputLabel value="Email:"/>
<apex:outputField value="{!Candidate__c.Email__c}" />
<apex:outputLabel value="Gender:"/>
<apex:outputField value="{!Candidate__c.Gender__c}"/>
</apex:panelGrid>
</apex:panelGroup>
</apex:panelGrid>
</apex:panelGrid>
<!-- Address Map -->
<apex:panelGrid columns="1" id="mapGrid" width="100%" border="1" frame="box" rules="none"
styleClass="photo" cellpadding="10" cellspacing="10" >
<apex:relatedList list="Job_Applications__r"/>
</apex:panelGrid>
<!-- after the Map let the user add details -->
</apex:page>
If you want to customize your data location in your forms Panelgroup & Panelgrid is one of the most usage tags.You can find recruiting application sign up as i mentioned in my previous post
http://bejawadabalayya.blogspot.com/2012/06/working-with-webservices-there-are-two.html
Visualforce page:
<apex:page standardController="Candidate__c">
<style type="text/css">
table.topTable{
border: 1px solid #d95d2e;
}
table.topTable td.photoCol{
text-align: right;
vertical-align: middle;
}
table.topTable td.fieldsCol{
text-align: left;
vertical-align: middle;
}
table.photo{
text-align: center;
vertical-align: middle;
}
table.data{
vertical-align: middle;
}
table.data td.label{
text-align: right;
font-weight: bold;
font-size: 1.5em;
}
table.data td.data{
text-align: left;
font-size: 1.5em;
}
h1.photo {
font-size: 2em;
}
</style>
<apex:insert name="header"/>
<!-- After the header show the photo and top level data -->
<apex:panelGrid columns="2" id="topTable" width="100%" border="1"
frame="box" rules="none"
styleClass="topTable" columnClasses="photoCol,fieldsCol"
cellpadding="5" cellspacing="5">
<!-- Picture Column -->
<apex:panelGrid columns="1" id="pictureGrid" styleClass="photo" width="100%"
cellpadding="10" cellspacing="10">
<apex:image url="{!Candidate__c.Picture_URL__c}"/>
<apex:outputText >
<hr width="80%"/>
<h1 class="photo">{!Candidate__c.First_Name__c} {!Candidate__c.Last_Name__c}</h1>
</apex:outputText>
</apex:panelGrid>
<apex:panelGrid columns="1" id="dataGrid" >
<apex:panelGroup >
<apex:panelGrid columns="2" styleClass="data" columnClasses="label,data">
<apex:outputLabel value="Phone:" />
<apex:outputField value="{!Candidate__c.Phone__c}"/>
<apex:outputLabel value="Mobile:"/>
<apex:outputField value="{!Candidate__c.Mobile__c}"/>
<apex:outputLabel value="Fax:"/>
<apex:outputField value="{!Candidate__c.Fax__c}"/>
<apex:outputLabel value="Email:"/>
<apex:outputField value="{!Candidate__c.Email__c}" />
<apex:outputLabel value="Gender:"/>
<apex:outputField value="{!Candidate__c.Gender__c}"/>
</apex:panelGrid>
</apex:panelGroup>
</apex:panelGrid>
</apex:panelGrid>
<!-- Address Map -->
<apex:panelGrid columns="1" id="mapGrid" width="100%" border="1" frame="box" rules="none"
styleClass="photo" cellpadding="10" cellspacing="10" >
<apex:relatedList list="Job_Applications__r"/>
</apex:panelGrid>
<!-- after the Map let the user add details -->
</apex:page>

ACTIVITY TAB:
ACTIVITY TAB:
How to make tasks and events as tab ,it is simple to achieve by enhancedlist and custom visualforce tab.The code looks like this
<apex:page > <apex:enhancedList type="Activity" height="600" />
</apex:page>

Also you can use multiple list views in the same page instead of going to different tabs like this
<apex:page >
<apex:enhancedList type="Account" height="250" />
<apex:enhancedList type="Contact" height="250" />
<apex:enhancedList type="Opportunity" height="250" />
</apex:page>
How to make tasks and events as tab ,it is simple to achieve by enhancedlist and custom visualforce tab.The code looks like this
<apex:page > <apex:enhancedList type="Activity" height="600" />
</apex:page>

Also you can use multiple list views in the same page instead of going to different tabs like this
<apex:page >
<apex:enhancedList type="Account" height="250" />
<apex:enhancedList type="Contact" height="250" />
<apex:enhancedList type="Opportunity" height="250" />
</apex:page>

Thursday, June 14, 2012
TABBED RELATED LIST:
TABBED RELATED LIST:
If you are working with more related list for detail records then it takes long time to scroll.The better option you can find as tabbing your related list .By using tabbing performance increased by 30 sec.More over you can use active tabs with one color in active with different colors using styles gives new look to your UI.The following example try with your custom or standard objects.
Visualforce Page:
<apex:page standardController="Engine_Type_Complete__c" showHeader="true" tabStyle="Engine_Type_Complete__c" >
<style>
.activeTab {background-color: #236FBD; color:white; background-image:none}
.inactiveTab { background-color: lightgrey; color:black; background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab=" tabdetails" id="AccountTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab" >
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail relatedList="false" title="true" inlineEdit="true"/>
</apex:tab>
<apex:tab label="Engine Repairs" name="Contacts" id="tabContact">
<apex:relatedList subject="{!Engine_Type_Complete__c}" list="Engine_Repairs__r" />
</apex:tab>
<apex:tab label="Engine Part Numbers" name="Opportunities" id="tabOpp">
<apex:relatedList subject="{!Engine_Type_Complete__c}" list="Engine_Repair_Parts__r" />
</apex:tab>
<apex:tab label="Engine Type Component Price History" name="OpenActivities" id="tabOpenAct">
<apex:relatedList subject="{!Engine_Type_Complete__c}" list="Engine_Type_Component_Price_History__r" />
</apex:tab>
</apex:tabPanel>
</apex:page>
If you are working with more related list for detail records then it takes long time to scroll.The better option you can find as tabbing your related list .By using tabbing performance increased by 30 sec.More over you can use active tabs with one color in active with different colors using styles gives new look to your UI.The following example try with your custom or standard objects.
Visualforce Page:
<apex:page standardController="Engine_Type_Complete__c" showHeader="true" tabStyle="Engine_Type_Complete__c" >
<style>
.activeTab {background-color: #236FBD; color:white; background-image:none}
.inactiveTab { background-color: lightgrey; color:black; background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab=" tabdetails" id="AccountTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab" >
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail relatedList="false" title="true" inlineEdit="true"/>
</apex:tab>
<apex:tab label="Engine Repairs" name="Contacts" id="tabContact">
<apex:relatedList subject="{!Engine_Type_Complete__c}" list="Engine_Repairs__r" />
</apex:tab>
<apex:tab label="Engine Part Numbers" name="Opportunities" id="tabOpp">
<apex:relatedList subject="{!Engine_Type_Complete__c}" list="Engine_Repair_Parts__r" />
</apex:tab>
<apex:tab label="Engine Type Component Price History" name="OpenActivities" id="tabOpenAct">
<apex:relatedList subject="{!Engine_Type_Complete__c}" list="Engine_Type_Component_Price_History__r" />
</apex:tab>
</apex:tabPanel>
</apex:page>

UITHEME:
UITHEME:
This post about new UI Themes of List Views.
Visualforce Page:
<apex:page showHeader="true" tabstyle="Case">
<apex:pageMessage severity="error" rendered="{!$User.UITheme = 'Theme3' &&
$User.UIThemeDisplayed != 'Theme3'}">
We've noticed that the new look and feel is enabled for your organization.
However, you can't take advantage of its brilliance. Please check with
your administrator for possible reasons for this impediment.
</apex:pageMessage>
<apex:ListViews type="Case" rendered="{!$User.UITheme = 'Theme3' &&
$User.UIThemeDisplayed = 'Theme3'}"/>
</apex:page>
Regular Theme:
UI Theme3
This post about new UI Themes of List Views.
Visualforce Page:
<apex:pageMessage severity="error" rendered="{!$User.UITheme = 'Theme3' &&
$User.UIThemeDisplayed != 'Theme3'}">
We've noticed that the new look and feel is enabled for your organization.
However, you can't take advantage of its brilliance. Please check with
your administrator for possible reasons for this impediment.
</apex:pageMessage>
<apex:ListViews type="Case" rendered="{!$User.UITheme = 'Theme3' &&
$User.UIThemeDisplayed = 'Theme3'}"/>
</apex:page>


EDIT ACCOUNT & IT'S CONTACTS:
EDIT ACCOUNT & IT'S CONTACTS:
This is a nice example shows how you can edit account and its related contacts using field sets in vf.
First create fieldset on account ,for example AccountsAndContactsEdit fieldset has account name,annual revenue,billing country and description and create another fieldset on contact AccountsAndContactsEdit has account name ,full name ,email,salutation.Now it is time to extension controller
Extension Controller:
public class AccountAndContactsEditExtension {
private ApexPages.StandardController std;
// the associated contacts
public List<Contact> contacts;
// the chosen contact id - used when deleting a contact
public Id chosenContactId {get; set;}
public String newContactFirstName {get; set;}
public String newContactLastName {get; set;}
public AccountAndContactsEditExtension()
{
}
public AccountAndContactsEditExtension(ApexPages.StandardController stdCtrl)
{
std=stdCtrl;
}
public Account getAccount()
{
return (Account) std.getRecord();
}
public SObject getSobject()
{
return std.getRecord();
}
private boolean updateContacts()
{
boolean result=true;
if (null!=contacts)
{
// TODO: should work out what's changed and then save, easier to update everything for prototype
List<Contact> updConts=new List<Contact>();
try
{
update contacts;
}
catch (Exception e)
{
String msg=e.getMessage();
integer pos;
// if its field validation, this will be added to the messages by default
if (-1==(pos=msg.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION, ')))
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg));
}
result=false;
}
}
return result;
}
public PageReference saveAndExit()
{
boolean result=true;
result=updateContacts();
if (result)
{
// call standard controller save
return std.save();
}
else
{
return null;
}
}
public PageReference save()
{
Boolean result=true;
PageReference pr=Page.AccountAndContactsEdit;
if (null!=getAccount().id)
{
result=updateContacts();
}
else
{
pr.setRedirect(true);
}
if (result)
{
// call standard controller save, but don't capture the return value which will redirect to view page
std.save();
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Changes saved'));
}
pr.getParameters().put('id', getAccount().id);
return pr;
}
public void newContact()
{
if (updateContacts())
{
Contact cont=new Contact(FirstName=newContactFirstName, LastName=newContactLastName, AccountId=getAccount().id);
insert cont;
newContactFirstName=null;
newContactLastName=null;
contacts=null;
}
}
public void deleteContact()
{
if (updateContacts())
{
if (null!=chosenContactId)
{
Contact cont=new Contact(Id=chosenContactId);
delete cont;
contacts=null;
chosenContactId=null;
}
}
}
public List<Contact> getContacts()
{
if ( (null!=getAccount().id) && (contacts == null) )
{
contacts=[SELECT Id, Name, Email, Phone, AccountId, Title,
Salutation, OtherStreet, OtherState, OtherPostalCode,
OtherPhone, OtherCountry, OtherCity, MobilePhone, MailingStreet, MailingState,
MailingPostalCode, MailingCountry, MailingCity, LeadSource, LastName,
HomePhone, FirstName, Fax, Description, Department
FROM Contact
WHERE AccountId = : getAccount().ID
ORDER BY CreatedDate];
}
return contacts;
}
}
Visualforce Page:
<apex:page standardController="Account"
extensions="AccountAndContactsEditExtension"
tabStyle="Account" title="Prototype Account Edit">
<apex:pageMessages />
<apex:form >
<apex:pageBlock mode="mainDetail">
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!cancel}" value="Exit" />
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton action="{!newContact}" value="New Contact" rendered="{!NOT(ISBLANK(Account.id))}" onclick="showpopup(); return false;"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Account Details" collapsible="true" id="mainRecord" columns="2" >
<apex:repeat value="{!$ObjectType.Account.FieldSets.AccountsAndContactsEdit}" var="field">
<apex:inputField value="{!Account[field]}" />
</apex:repeat>
</apex:pageBlockSection>
<apex:outputPanel id="contactList">
<apex:repeat value="{!contacts}" var="contact" >
<apex:pageBlockSection columns="1" title="Contact {!contact.Name}" collapsible="true">
<apex:pageBlockSectionItem >
<apex:pageBlockSection columns="2">
<apex:repeat value="{!$ObjectType.Contact.FieldSets.AccountsAndContactsEdit}" var="field">
<apex:inputField value="{!contact[field]}" />
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<div style="text-align:center">
<apex:commandButton value="Delete This Contact" onclick="idToDelete='{!contact.id}'; showpopup('deletecontent'); return false;"/>
</div>
</apex:repeat>
</apex:outputPanel>
</apex:pageBlock>
<apex:outputPanel id="addPanel">
<apex:actionRegion id="popupRegion">
<div id="opaque"/>
<div id="popupcontent" class="popupcontent" style="width: 250px; height: 100px;">
Please enter the new contact details
<apex:outputLabel value="First Name: "/><apex:inputText id="newfirst" value="{!newContactFirstName}"/>
<apex:outputLabel value="Last Name: "/><apex:inputText id="newlast" value="{!newContactLastName}"/>
<apex:commandButton id="cancelBtn" value="Cancel" onclick="hidepopup(); return false;"/>
<apex:commandButton id="confirmBtn" action="{!newContact}" value="Create" rerender="contactList, addPanel" onclick="hidepopup();" status="working"/>
</div>
</apex:actionRegion>
</apex:outputPanel>
<apex:actionRegion id="deleteRegion">
<div id="deletecontent" class="popupcontent" style="width: 250px; height: 100px;">
Are you sure you wish to delete contact?
<apex:commandButton id="cancelDelBtn" value="Cancel" onclick="hidepopup('deletecontent'); return false;"/>
<apex:commandButton id="confirmDelBtn" value="Delete" rerender="contactList" onclick="hidepopup('deletecontent'); alert('Deleting contact ' + idToDelete); deleteContact(idToDelete); return false;" status="working"/>
</div>
</apex:actionRegion>
<apex:actionFunction name="deleteContact" action="{!deleteContact}" rerender="contactList" status="working">
<apex:param name="contactIdent" value="" assignTo="{!chosenContactId}"/>
</apex:actionFunction>
</apex:form>
<div id="workingcontent" class="popupcontent" style="width:150px; height:50px; margin-top:-100px; marginleft:-100px">
<p align="center" style='{font-family:"Arial", Helvetica, sans-serif; font-size:20px;}'><apex:image value="/img/loading.gif"/> Please wait</p>
</div>
<apex:actionStatus id="working" onstart="showpopup('workingcontent');" onstop="hidepopup('workingcontent');" />
<script>
function showpopup(popupname)
{
var name="popupcontent";
if (popupname)
{
name=popupname;
}
var popUp = document.getElementById(name);
popUp.style.display = "block";
document.getElementById('opaque').style.display='block';
}
function hidepopup(popupname)
{
var name="popupcontent";
if (popupname)
{
name=popupname;
}
var popUp = document.getElementById(name);
popUp.style.display = "none";
document.getElementById('opaque').style.display='none';
}
var idToDelete;
</script>
<style>
.popupcontent{
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
display: none;
overflow: auto;
border:1px solid #CCC;
background-color:white;
border:3px solid #333;
z-index:100;
padding:5px;
line-height:20px;
font-size: 14px;
}
#opaque {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 1;
display: none;
background-color: gray;
filter: alpha(opacity=30);
opacity: 0.3;
-moz-opacity:0.3;
-khtml-opacity:0.3
}
* html #opaque {
position: absolute;
}
</style>
</apex:page>
This is a nice example shows how you can edit account and its related contacts using field sets in vf.
First create fieldset on account ,for example AccountsAndContactsEdit fieldset has account name,annual revenue,billing country and description and create another fieldset on contact AccountsAndContactsEdit has account name ,full name ,email,salutation.Now it is time to extension controller
Extension Controller:
public class AccountAndContactsEditExtension {
private ApexPages.StandardController std;
// the associated contacts
public List<Contact> contacts;
// the chosen contact id - used when deleting a contact
public Id chosenContactId {get; set;}
public String newContactFirstName {get; set;}
public String newContactLastName {get; set;}
public AccountAndContactsEditExtension()
{
}
public AccountAndContactsEditExtension(ApexPages.StandardController stdCtrl)
{
std=stdCtrl;
}
public Account getAccount()
{
return (Account) std.getRecord();
}
public SObject getSobject()
{
return std.getRecord();
}
private boolean updateContacts()
{
boolean result=true;
if (null!=contacts)
{
// TODO: should work out what's changed and then save, easier to update everything for prototype
List<Contact> updConts=new List<Contact>();
try
{
update contacts;
}
catch (Exception e)
{
String msg=e.getMessage();
integer pos;
// if its field validation, this will be added to the messages by default
if (-1==(pos=msg.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION, ')))
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg));
}
result=false;
}
}
return result;
}
public PageReference saveAndExit()
{
boolean result=true;
result=updateContacts();
if (result)
{
// call standard controller save
return std.save();
}
else
{
return null;
}
}
public PageReference save()
{
Boolean result=true;
PageReference pr=Page.AccountAndContactsEdit;
if (null!=getAccount().id)
{
result=updateContacts();
}
else
{
pr.setRedirect(true);
}
if (result)
{
// call standard controller save, but don't capture the return value which will redirect to view page
std.save();
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Changes saved'));
}
pr.getParameters().put('id', getAccount().id);
return pr;
}
public void newContact()
{
if (updateContacts())
{
Contact cont=new Contact(FirstName=newContactFirstName, LastName=newContactLastName, AccountId=getAccount().id);
insert cont;
newContactFirstName=null;
newContactLastName=null;
contacts=null;
}
}
public void deleteContact()
{
if (updateContacts())
{
if (null!=chosenContactId)
{
Contact cont=new Contact(Id=chosenContactId);
delete cont;
contacts=null;
chosenContactId=null;
}
}
}
public List<Contact> getContacts()
{
if ( (null!=getAccount().id) && (contacts == null) )
{
contacts=[SELECT Id, Name, Email, Phone, AccountId, Title,
Salutation, OtherStreet, OtherState, OtherPostalCode,
OtherPhone, OtherCountry, OtherCity, MobilePhone, MailingStreet, MailingState,
MailingPostalCode, MailingCountry, MailingCity, LeadSource, LastName,
HomePhone, FirstName, Fax, Description, Department
FROM Contact
WHERE AccountId = : getAccount().ID
ORDER BY CreatedDate];
}
return contacts;
}
}
Visualforce Page:
<apex:page standardController="Account"
extensions="AccountAndContactsEditExtension"
tabStyle="Account" title="Prototype Account Edit">
<apex:pageMessages />
<apex:form >
<apex:pageBlock mode="mainDetail">
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!cancel}" value="Exit" />
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton action="{!newContact}" value="New Contact" rendered="{!NOT(ISBLANK(Account.id))}" onclick="showpopup(); return false;"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Account Details" collapsible="true" id="mainRecord" columns="2" >
<apex:repeat value="{!$ObjectType.Account.FieldSets.AccountsAndContactsEdit}" var="field">
<apex:inputField value="{!Account[field]}" />
</apex:repeat>
</apex:pageBlockSection>
<apex:outputPanel id="contactList">
<apex:repeat value="{!contacts}" var="contact" >
<apex:pageBlockSection columns="1" title="Contact {!contact.Name}" collapsible="true">
<apex:pageBlockSectionItem >
<apex:pageBlockSection columns="2">
<apex:repeat value="{!$ObjectType.Contact.FieldSets.AccountsAndContactsEdit}" var="field">
<apex:inputField value="{!contact[field]}" />
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<div style="text-align:center">
<apex:commandButton value="Delete This Contact" onclick="idToDelete='{!contact.id}'; showpopup('deletecontent'); return false;"/>
</div>
</apex:repeat>
</apex:outputPanel>
</apex:pageBlock>
<apex:outputPanel id="addPanel">
<apex:actionRegion id="popupRegion">
<div id="opaque"/>
<div id="popupcontent" class="popupcontent" style="width: 250px; height: 100px;">
Please enter the new contact details
<apex:outputLabel value="First Name: "/><apex:inputText id="newfirst" value="{!newContactFirstName}"/>
<apex:outputLabel value="Last Name: "/><apex:inputText id="newlast" value="{!newContactLastName}"/>
<apex:commandButton id="cancelBtn" value="Cancel" onclick="hidepopup(); return false;"/>
<apex:commandButton id="confirmBtn" action="{!newContact}" value="Create" rerender="contactList, addPanel" onclick="hidepopup();" status="working"/>
</div>
</apex:actionRegion>
</apex:outputPanel>
<apex:actionRegion id="deleteRegion">
<div id="deletecontent" class="popupcontent" style="width: 250px; height: 100px;">
Are you sure you wish to delete contact?
<apex:commandButton id="cancelDelBtn" value="Cancel" onclick="hidepopup('deletecontent'); return false;"/>
<apex:commandButton id="confirmDelBtn" value="Delete" rerender="contactList" onclick="hidepopup('deletecontent'); alert('Deleting contact ' + idToDelete); deleteContact(idToDelete); return false;" status="working"/>
</div>
</apex:actionRegion>
<apex:actionFunction name="deleteContact" action="{!deleteContact}" rerender="contactList" status="working">
<apex:param name="contactIdent" value="" assignTo="{!chosenContactId}"/>
</apex:actionFunction>
</apex:form>
<div id="workingcontent" class="popupcontent" style="width:150px; height:50px; margin-top:-100px; marginleft:-100px">
<p align="center" style='{font-family:"Arial", Helvetica, sans-serif; font-size:20px;}'><apex:image value="/img/loading.gif"/> Please wait</p>
</div>
<apex:actionStatus id="working" onstart="showpopup('workingcontent');" onstop="hidepopup('workingcontent');" />
<script>
function showpopup(popupname)
{
var name="popupcontent";
if (popupname)
{
name=popupname;
}
var popUp = document.getElementById(name);
popUp.style.display = "block";
document.getElementById('opaque').style.display='block';
}
function hidepopup(popupname)
{
var name="popupcontent";
if (popupname)
{
name=popupname;
}
var popUp = document.getElementById(name);
popUp.style.display = "none";
document.getElementById('opaque').style.display='none';
}
var idToDelete;
</script>
<style>
.popupcontent{
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
display: none;
overflow: auto;
border:1px solid #CCC;
background-color:white;
border:3px solid #333;
z-index:100;
padding:5px;
line-height:20px;
font-size: 14px;
}
#opaque {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 1;
display: none;
background-color: gray;
filter: alpha(opacity=30);
opacity: 0.3;
-moz-opacity:0.3;
-khtml-opacity:0.3
}
* html #opaque {
position: absolute;
}
</style>
</apex:page>

Monday, June 11, 2012
SEARCH:
SEARCH:
This is regarding searching.Search in salesforce has its own drawbacks especially with keywords and sorting.
Controller:
public List<Lead> resultListLeads;
public List<Contact> resultListContacts;
public List<Account> resultListAccounts;
public String searchFirstname{ get; set; }
public String searchLastname{ get; set; }
public String searchCompany{ get; set; }
public String searchPhone{ get; set; }
public String searchEmail{ get; set; }
public boolean noLeadResult{ get; set; }
public boolean noContactResult{ get; set; }
public boolean noAccountResult{ get; set; }
public boolean emptyLeadList{ get; set; }
public boolean emptyContactList{ get; set; }
public boolean emptyAccountList{ get; set; }
public boolean errorShow{ get; set; }
public String errorTitle{ get; set; }
public String errorMessage{ get; set; }
public String errorSeverity{ get; set; }
public Integer numLeads{ get; set; }
public Integer numContacts{ get; set; }
public Integer numAccounts{ get; set; }
public SearchFirstController ( ) {
emptyLeadList = true;
emptyContactList = true;
emptyAccountList = true;
numLeads = 0;
numContacts = 0;
numAccounts = 0;
noLeadResult = false;
noContactResult = false;
noAccountResult = false;
errorShow = false;
errorTitle = '';
errorMessage = '';
errorSeverity = '';
}
public List<Lead> getresultListLeads() {
return resultListLeads;
}
public List<Contact> getresultListContacts() {
return resultListContacts;
}
public List<Account> getresultListAccounts() {
return resultListAccounts;
}
public PageReference search() {
errorShow = false;
string tablesFields = 'lead(id, phone, company, email, firstname, Status, lastname), contact(id, phone, email, firstname, lastname, accountId), account(id, phone, type, name)';
string searchString = getSearchCriteria();
string checkString = searchString.replace('*','').replace('?','');
if (checkString.length() > 1) {
try {
searchString = 'find \'' + searchString + '\' in ALL FIELDS RETURNING ' + tablesFields;
searchResults = search.query(searchString);
resultListLeads = ((List<Lead>)searchResults[0]);
numLeads = resultListLeads.size();
emptyLeadList = resultListLeads.isEmpty() ? true : false;
noLeadResult = emptyLeadList;
resultListContacts = ((List<Contact>)searchResults[1]);
numContacts = resultListContacts.size();
emptyContactList = resultListContacts.isEmpty() ? true : false;
noContactResult = emptyContactList;
resultListAccounts = ((List<Account>)searchResults[2]);
numAccounts = resultListAccounts.size();
emptyAccountList = resultListAccounts.isEmpty() ? true : false;
noAccountResult = emptyAccountList;
} catch (Exception e) {
// System.debug('Error when executing the search: ' + e);
errorTitle = e.getMessage();
errorMessage = e.getMessage();
errorSeverity = 'error';
errorShow = true;
}
} else if (checkString.length() == 1) {
numLeads = 0;
numContacts = 0;
numAccounts = 0;
emptyLeadList = true;
emptyContactList = true;
emptyAccountList = true;
noLeadResult = false;
noContactResult = false;
noAccountResult = false;
errorTitle = System.Label.sfError;
errorMessage = System.Label.sfErrorMessage ;
errorSeverity = 'error';
errorShow = true;
}
// return to the same page
return null;
}
public PageReference reset() {
numLeads = 0;
numContacts = 0;
numAccounts = 0;
emptyLeadList = true;
emptyContactList = true;
emptyAccountList = true;
searchFirstname = '';
searchLastname = '';
searchCompany = '';
searchPhone = '';
searchEmail = '';
errorTitle = '';
errorMessage = '';
errorSeverity = '';
errorShow = false;
noLeadResult = false;
noContactResult = false;
noAccountResult = false;
return null;
}
private string getSearchCriteria() {
String fullSearchString = '';
String searchName = searchFirstname;
if (searchName != ''){
if (searchLastname != '') {
searchName = searchFirstname + ' ' + searchLastname;
}
} else {
searchName = searchLastname;
}
fullSearchString = appendToSearchString(fullSearchString, searchName);
fullSearchString = appendToSearchString(fullSearchString, searchCompany);
fullSearchString = appendToSearchString(fullSearchString, searchPhone);
fullSearchString = appendToSearchString(fullSearchString, searchEmail);
return fullSearchString;
}
public PageReference createNewLead(){
PageReference pageRef = new PageReference('/00Q/e?retURL=%2F00Q%2Fo' + (searchCompany != ''?'&lea3='+ searchCompany : '') + (searchFirstname != ''?'&name_firstlea2='+ searchFirstname : '') + (searchLastname != ''?'&name_lastlea2='+ searchLastname : '') + (searchPhone != ''?'&lea8='+ searchPhone : '') + (searchEmail != ''?'&lea11='+ searchEmail : ''));
return pageRef;
}
public PageReference createNewContact(){
PageReference pageRef = new PageReference('/003/e?retURL=%2F003%2Fo' + (searchFirstname != ''?'&name_firstcon2='+ searchFirstname : '') + (searchLastname != ''?'&name_lastcon2='+ searchLastname : '') + (searchPhone != ''?'&con10='+ searchPhone : '') + (searchEmail != ''?'&con15='+ searchEmail : ''));
return pageRef; // + (searchCompany != ''?'&con4='+ searchCompany : '')
}
public PageReference createNewAccount(){
PageReference pageRef = new PageReference('/001/e?retURL=%2F001%2Fo' + (searchCompany != ''?'&acc2='+ searchCompany : '') );
return pageRef;
}
private string appendToSearchString(String searchString, String newValue) {
if (newValue != '') {
if (searchString == '') {
searchString = newValue;
} else {
searchString += ' OR ' + newValue;
}
}
return searchString;
}
}
This is regarding searching.Search in salesforce has its own drawbacks especially with keywords and sorting.
Controller:
public with sharing class SearchFirstController {
protected List<List<sObject>> searchResults = new List<List<sObject>>{};public List<Lead> resultListLeads;
public List<Contact> resultListContacts;
public List<Account> resultListAccounts;
public String searchFirstname{ get; set; }
public String searchLastname{ get; set; }
public String searchCompany{ get; set; }
public String searchPhone{ get; set; }
public String searchEmail{ get; set; }
public boolean noLeadResult{ get; set; }
public boolean noContactResult{ get; set; }
public boolean noAccountResult{ get; set; }
public boolean emptyLeadList{ get; set; }
public boolean emptyContactList{ get; set; }
public boolean emptyAccountList{ get; set; }
public boolean errorShow{ get; set; }
public String errorTitle{ get; set; }
public String errorMessage{ get; set; }
public String errorSeverity{ get; set; }
public Integer numLeads{ get; set; }
public Integer numContacts{ get; set; }
public Integer numAccounts{ get; set; }
public SearchFirstController ( ) {
emptyLeadList = true;
emptyContactList = true;
emptyAccountList = true;
numLeads = 0;
numContacts = 0;
numAccounts = 0;
noLeadResult = false;
noContactResult = false;
noAccountResult = false;
errorShow = false;
errorTitle = '';
errorMessage = '';
errorSeverity = '';
}
public List<Lead> getresultListLeads() {
return resultListLeads;
}
public List<Contact> getresultListContacts() {
return resultListContacts;
}
public List<Account> getresultListAccounts() {
return resultListAccounts;
}
public PageReference search() {
errorShow = false;
string tablesFields = 'lead(id, phone, company, email, firstname, Status, lastname), contact(id, phone, email, firstname, lastname, accountId), account(id, phone, type, name)';
string searchString = getSearchCriteria();
string checkString = searchString.replace('*','').replace('?','');
if (checkString.length() > 1) {
try {
searchString = 'find \'' + searchString + '\' in ALL FIELDS RETURNING ' + tablesFields;
searchResults = search.query(searchString);
resultListLeads = ((List<Lead>)searchResults[0]);
numLeads = resultListLeads.size();
emptyLeadList = resultListLeads.isEmpty() ? true : false;
noLeadResult = emptyLeadList;
resultListContacts = ((List<Contact>)searchResults[1]);
numContacts = resultListContacts.size();
emptyContactList = resultListContacts.isEmpty() ? true : false;
noContactResult = emptyContactList;
resultListAccounts = ((List<Account>)searchResults[2]);
numAccounts = resultListAccounts.size();
emptyAccountList = resultListAccounts.isEmpty() ? true : false;
noAccountResult = emptyAccountList;
} catch (Exception e) {
// System.debug('Error when executing the search: ' + e);
errorTitle = e.getMessage();
errorMessage = e.getMessage();
errorSeverity = 'error';
errorShow = true;
}
} else if (checkString.length() == 1) {
numLeads = 0;
numContacts = 0;
numAccounts = 0;
emptyLeadList = true;
emptyContactList = true;
emptyAccountList = true;
noLeadResult = false;
noContactResult = false;
noAccountResult = false;
errorTitle = System.Label.sfError;
errorMessage = System.Label.sfErrorMessage ;
errorSeverity = 'error';
errorShow = true;
}
// return to the same page
return null;
}
public PageReference reset() {
numLeads = 0;
numContacts = 0;
numAccounts = 0;
emptyLeadList = true;
emptyContactList = true;
emptyAccountList = true;
searchFirstname = '';
searchLastname = '';
searchCompany = '';
searchPhone = '';
searchEmail = '';
errorTitle = '';
errorMessage = '';
errorSeverity = '';
errorShow = false;
noLeadResult = false;
noContactResult = false;
noAccountResult = false;
return null;
}
private string getSearchCriteria() {
String fullSearchString = '';
String searchName = searchFirstname;
if (searchName != ''){
if (searchLastname != '') {
searchName = searchFirstname + ' ' + searchLastname;
}
} else {
searchName = searchLastname;
}
fullSearchString = appendToSearchString(fullSearchString, searchName);
fullSearchString = appendToSearchString(fullSearchString, searchCompany);
fullSearchString = appendToSearchString(fullSearchString, searchPhone);
fullSearchString = appendToSearchString(fullSearchString, searchEmail);
return fullSearchString;
}
public PageReference createNewLead(){
PageReference pageRef = new PageReference('/00Q/e?retURL=%2F00Q%2Fo' + (searchCompany != ''?'&lea3='+ searchCompany : '') + (searchFirstname != ''?'&name_firstlea2='+ searchFirstname : '') + (searchLastname != ''?'&name_lastlea2='+ searchLastname : '') + (searchPhone != ''?'&lea8='+ searchPhone : '') + (searchEmail != ''?'&lea11='+ searchEmail : ''));
return pageRef;
}
public PageReference createNewContact(){
PageReference pageRef = new PageReference('/003/e?retURL=%2F003%2Fo' + (searchFirstname != ''?'&name_firstcon2='+ searchFirstname : '') + (searchLastname != ''?'&name_lastcon2='+ searchLastname : '') + (searchPhone != ''?'&con10='+ searchPhone : '') + (searchEmail != ''?'&con15='+ searchEmail : ''));
return pageRef; // + (searchCompany != ''?'&con4='+ searchCompany : '')
}
public PageReference createNewAccount(){
PageReference pageRef = new PageReference('/001/e?retURL=%2F001%2Fo' + (searchCompany != ''?'&acc2='+ searchCompany : '') );
return pageRef;
}
private string appendToSearchString(String searchString, String newValue) {
if (newValue != '') {
if (searchString == '') {
searchString = newValue;
} else {
searchString += ' OR ' + newValue;
}
}
return searchString;
}
}
VISUALFORCE PAGE:
<apex:page controller="SearchFirstController" tabStyle="Search_Create__tab">
<apex:sectionHeader title="{!$Label.sfTitle}" subtitle="Search For Accounts and Contacts" description="{!$Label.sfTitleDescription}"/>
<apex:outputPanel id="errorPanel">
<apex:pageMessage strength="2" title="{!errorTitle}" summary="{!errorMessage}" severity="{!errorSeverity}" rendered="{!errorShow}" />
</apex:outputPanel>
<apex:outputPanel id="searchPanel" styleClass="searchFilterFields">
<apex:form id="searchForm">
<div class="searchFilterFieldsHolder">
<table class="searchFilterFields" width="100%">
<tr>
<td width="250px">
<table width="100%">
<tr>
<td>
<apex:outputLabel value="{!$Label.sfAccount}" for="searchCompany"/>
</td>
<td width="100%">
<apex:inputText value="{!searchCompany}" id="searchCompany" required="false"/>
</td>
</tr>
<tr>
<tr>
<td>
<apex:outputLabel value="{!$Label.sfFirstName}" for="searchFirstName"/>
</td>
<td width="100%">
<apex:inputText value="{!searchFirstName}" id="searchFirstName" required="false"/>
</td>
</tr>
<tr>
<td>
<apex:outputLabel value="{!$Label.sfLastName}" for="searchLastName"/>
</td>
<td width="100%">
<apex:inputText value="{!searchLastname}" id="searchLastName" required="false"/>
</td>
</tr>
<td>
<apex:outputLabel value="{!$Label.sfPhone}" for="searchdPhone"/>
</td>
<td width="100%">
<apex:inputText value="{!searchPhone}" id="searchPhone" required="false"/>
</td>
</tr>
<tr>
<td>
<apex:outputLabel value="{!$Label.sfEmail}" for="searchEmail"/>
</td>
<td width="100%">
<apex:inputText value="{!searchEmail}" id="searchEmail" required="false"/>
</td>
</tr>
<tr>
<td>
</td>
<td width="100%">
<apex:commandButton value="{!$Label.btnSearch}" action="{!search}" rerender="resultPanel,errorPanel" styleClass="searchFilterButton" status="processingStatus"/> <apex:commandButton value="{!$Label.btnReset}" action="{!reset}" rerender="searchPanel,resultPanel,errorPanel" styleClass="searchFilterButton"/>
</td>
</tr>
</table>
</td>
<td align="center" valign="middle"><table style="font-size:80%;"><tr><td width="20%" align="right"><strong>{!$Label.sfAsterik}</strong></td><td width="80%">{!$Label.sfAsterikText}</td></tr><tr><td width="20%" align="right"><strong>{!$Label.sfQuestionmark}</strong></td><td width="80%">{!$Label.sfQuestionmarkText}</td></tr></table></td></tr></table>
</div>
</apex:form>
<center><apex:actionStatus id="processingStatus" startText="{!$Label.sfProcessRequest}"/></center>
</apex:outputPanel>
<br/>
<apex:outputPanel id="resultPanel">
<apex:form id="resultForm">
<apex:pageBlock id="accountresultPanel" title="{!$Label.sfAccounts}{!If(numAccounts > 0,' [' & text(numAccounts) & ']',' [0]')}" tabStyle="Account">
<apex:pageMessage strength="2" severity="info" summary="{!$Label.sfNoAccountResultWarning}" rendered="{!noAccountResult}" />
<apex:pageBlockSection title="{!$Label.sfMatchingAccounts}" collapsible="true" columns="1" rendered="{!NOT(emptyAccountList)}">
<apex:pageBlockTable value="{!resultListAccounts}" var="accountItem">
<apex:column >
<apex:facet name="header">{!$Label.sfAccountName}</apex:facet>
<apex:outputLink value="{!URLFOR($Action.Account.View, accountItem.Id)}">{!accountItem.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!accountItem.Phone}"/>
<apex:column value="{!accountItem.Type}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton id="createNewAccount" value="{!$Label.btnNew}" action="{!createNewAccount}"/>
</apex:pageBlock>
<apex:pageBlock id="contactresultPanel" title="{!$Label.sfContacts}{!If(numContacts > 0,' [' & text(numContacts) & ']',' [0]')}" tabStyle="Contact">
<apex:pageMessage strength="2" severity="info" summary="{!$Label.sfNoContactResultWarning}" rendered="{!noContactResult}" />
<apex:pageBlockSection title="{!$Label.sfMatchingContacts}" collapsible="true" columns="1" rendered="{!NOT(emptyContactList)}">
<apex:pageBlockTable value="{!resultListContacts}" var="contactItem">
<apex:column >
<apex:facet name="header">{!$Label.sfContactName}</apex:facet>
<apex:outputLink value="{!URLFOR($Action.Contact.View, contactItem.Id)}">{!contactItem.Firstname} {!contactItem.Lastname}</apex:outputLink>
</apex:column>
<!-- <apex:column value="{!contactItem.Company}"/>-->
<apex:column value="{!contactItem.Phone}"/>
<apex:column value="{!contactItem.Email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton id="createNewLead" value="{!$Label.btnNew}" action="{!createNewContact}"/>
</apex:pageBlock>
</apex:form>
</apex:outputPanel>
</apex:page>
TEST CLASS:
@isTest private class SearchFirstTest { static testMethod void myUnitTest() { Test.starttest(); PageReference testPage = Page.searchfirst; Test.setCurrentPage(testPage); SearchFirstController myController = new SearchFirstController(); myController.searchFirstname = ''; myController.searchLastname = ''; myController.searchCompany = ''; myController.searchPhone = ''; myController.searchEmail = ''; myController.noLeadResult = true; myController.noContactResult = true; myController.noAccountResult = true; myController.emptyLeadList = true; myController.emptyContactList = true; myController.emptyAccountList = true; myController.numLeads = 0; myController.numContacts = 0; myController.numAccounts = 0; myController.errorShow = true; myController.errorTitle = ''; myController.errorMessage = ''; myController.errorSeverity = ''; myController.getresultListLeads(); myController.getresultListContacts(); myController.getresultListAccounts(); System.assertEquals('',myController.searchFirstname); System.assertEquals('',myController.searchLastname); System.assertEquals('',myController.searchCompany); System.assertEquals('',myController.searchPhone); System.assertEquals('',myController.searchEmail); System.assert(myController.noLeadResult); System.assert(myController.noContactResult); System.assert(myController.noAccountResult); System.assert(myController.emptyLeadList); System.assert(myController.emptyContactList); System.assert(myController.emptyAccountList); System.assert(myController.errorShow); System.assertEquals('',myController.errorTitle); System.assertEquals('',myController.errorMessage); System.assertEquals('',myController.errorSeverity); myController.search(); myController.createNewLead(); myController.createNewContact(); myController.createNewAccount(); myController.searchFirstname = 'Test'; myController.searchLastname = ''; myController.searchCompany = 'Test'; myController.searchPhone = '345345'; myController.searchEmail = '435345@test.com'; myController.search(); myController.searchFirstname = ''; myController.searchLastname = 'Test'; myController.searchCompany = 'Test'; myController.searchPhone = '345345'; myController.searchEmail = '435345@test.com'; myController.search(); myController.searchFirstname = 'Test'; myController.searchLastname = 'Test'; myController.searchCompany = 'Test'; myController.searchPhone = '345345'; myController.searchEmail = '435345@test.com'; myController.search(); myController.searchFirstname = ''; myController.searchLastname = ''; myController.searchCompany = 'x'; myController.searchPhone = ''; myController.searchEmail = ''; myController.search(); myController.createNewLead(); myController.createNewContact(); myController.createNewAccount(); myController.reset(); Test.stoptest(); } } |

POPULATE CUSTOM FIELD:
POPULATE CUSTOM FIELD:
This is a simple trigger populate custom field on contact from mobile number standard field.Area code is your custom field should be populate with part of the mobile number.
Apex Trigger:
trigger GenerateTextEmail on Contact (before insert, before update)
{
for (Contact objCon : Trigger.new)
{
String areaCode = '';
if (objCon.MobilePhone == null)
{
// can't populate the Area Code field if there is no number saved
}
else
{
String temp = '';
if(objCon.MobilePhone != null)
temp = objCon.MobilePhone;
if (temp == null || temp == '') {}
else if (temp.length() == 10)
{
areaCode = temp.substring(0,3);
}
else
{
areaCode = temp.substring(1,4);
}
}
if(areaCode != null && areaCode != '')
objCon.Area_Code__c = areaCode;
}
}
This is a simple trigger populate custom field on contact from mobile number standard field.Area code is your custom field should be populate with part of the mobile number.
Apex Trigger:
trigger GenerateTextEmail on Contact (before insert, before update)
{
for (Contact objCon : Trigger.new)
{
String areaCode = '';
if (objCon.MobilePhone == null)
{
// can't populate the Area Code field if there is no number saved
}
else
{
String temp = '';
if(objCon.MobilePhone != null)
temp = objCon.MobilePhone;
if (temp == null || temp == '') {}
else if (temp.length() == 10)
{
areaCode = temp.substring(0,3);
}
else
{
areaCode = temp.substring(1,4);
}
}
if(areaCode != null && areaCode != '')
objCon.Area_Code__c = areaCode;
}
}

Subscribe to:
Posts (Atom)