You need to sign in to do that
Don't have an account?
ethan hunt
Trigger To Copy address from one field to another
Hi,
I have two text field A & B and one checkbox. I want when i click the check box address from A will get copy to B before saving.
Could you please suggest what should i do. Weather a trigger, Workflow or formula field.
Regards
I have two text field A & B and one checkbox. I want when i click the check box address from A will get copy to B before saving.
Could you please suggest what should i do. Weather a trigger, Workflow or formula field.
Regards
I think Trigger is the best option to acheive this task .
You can write trigger on before insert event of your object .
// For example : Suppose your object is Account
if(trigger.isInsert && trigger.isBefore)
{
for( Account objacc : Trigger.New)
{
if(objacc.chkboxfield == true)
{
if(objacc.fieldA !=null)
objacc.fieldB = objacc.fieldA ;
}
}
}
Because, I guess that you are expecting this functionality to happen before the save click and right after the checkbox is ticked, am I right?
If I am right, you can not have this before save click in standard record edit page(and the trigger is fired after the save button is clicked) but is possible if this is a visual force page.
Regards
-Harsha.
Trigger will not work because trigger will execute when ever dml operaion done.
This can be done by writing method and pass all the fields from and to then pass that method to that checkbox.
OR
By Javascript you can copy before saving i.e just on click the checkbox copy the fields values from one fields to another fields.
Regards,
Rajesh.
I am using the folloiwng javascript function but it is not working.Kindly check if something is missing
<apex:page standardController="Invoice__c" >
<apex:form >
<script>
function FillBilling()
{
var cb = document.getElementById('ic1').value;
var tb1 = document.getElementById('it1').value;
var tb2 = document.getElementById('it2').value;
if (cb.checked)
{
tb2 = tb1;
}
else
{
tb2 = '';
}
}
</script>
<apex:inputText value="{!Invoice__c.Billing_Address__c}" id="it1"/> <br/>
<apex:inputCheckbox value="{!Invoice__c.Copy_Mailing_Address__c}" id="ic1" onclick="FillBilling()"/> <br/>
<apex:inputText value="{!Invoice__c.Mailing_Address__c}" id="it2" />
</apex:form>
</apex:page>
Regards
One can not access the visualforce components directly in javascript as below.
var cb = document.getElementById('ic1').value;
var tb1 = document.getElementById('it1').value;
var tb2 = document.getElementById('it2').value;
Instead, have to use it as below:
var cb = document.getElementById('{!$Component.ic1}').value;
var tb1 = document.getElementById('{!$Component.it1}').value;
var tb2 = document.getElementById('{!$Component.it2}').value;
Refer http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_component.htm to better know.
Regards,
Harsha
for(contact a:trigger.new)
{
if(a.Copy_Address__c ==True)
a.MailingAddress = a.OtherAddress ;
}
}