write a trigger on contact to update the mobile number with the country isd code. like if a new contact is insert or update and the contact country value or mobile number changed then trigger should run and it will check the country of contact record.
You can achieve this using workflow too. Advantage over trigger is that you dont have to need a coder/developer in case you need to do minor changes. Also you need not write test class to migrate it to production.
Here is what you need to do in a workflow:
Create a workflow rule on Contact object
Set the Evaluation Criteria to Evaluate the rule when a record is created, and every time it’s edited
Set the rule criteria to:
AND ( OR ( NOT( ISPICKVAL(leadtherace__CountryISDCode__c, '')), ISCHANGED(leadtherace__CountryISDCode__c) ), NOT( ISBLANK (MobilePhone) )
I have tested this. It works fine. Please let me know if you need clarification on anything I have mentioned. If you want trigger, please do the similar logic in the trigger code.
when i update the custom field countryIsdCode with other country then it is not updated to the new value .its also maintain its previous value.i am getting result in this way which is not correct.+01+91+65+65+65+91(457) 896-8744. i want only one isd code which must be updated then how colud i solve it.
You can achieve this using workflow too. Advantage over trigger is that you dont have to need a coder/developer in case you need to do minor changes. Also you need not write test class to migrate it to production.
Here is what you need to do in a workflow:
Create a workflow rule on Contact object
Set the Evaluation Criteria to Evaluate the rule when a record is created, and every time it’s edited
Set the rule criteria to:
AND ( OR ( NOT( ISPICKVAL(leadtherace__CountryISDCode__c, '')), ISCHANGED(leadtherace__CountryISDCode__c) ), NOT( ISBLANK (MobilePhone) )
I have tested this. It works fine. Please let me know if you need clarification on anything I have mentioned. If you want trigger, please do the similar logic in the trigger code.
Thanks.. it works fine using workflow but i tried it using trigger but its not working can you please give me idea that how to resolve it for update using Trigger.
Here is what you need to do in a workflow:
OR (
NOT( ISPICKVAL(leadtherace__CountryISDCode__c, '')),
ISCHANGED(leadtherace__CountryISDCode__c)
),
NOT( ISBLANK (MobilePhone) )
- Now add a Field Update on Mobile field
- The formula would look like:
- IF( BEGINS( MobilePhone, '+'),
I have tested this. It works fine. Please let me know if you need clarification on anything I have mentioned. If you want trigger, please do the similar logic in the trigger code.IF( ISPICKVAL (CountryISDCode__c, 'singapore'),
('+65' & ( RIGHT (MobilePhone, LEN (MobilePhone)-3))),
IF( ISPICKVAL (CountryISDCode__c, 'india'),
('+91' & ( RIGHT (MobilePhone, LEN (MobilePhone)-3))),
IF( ISPICKVAL (CountryISDCode__c, 'us'),
('+01' & ( RIGHT (MobilePhone, LEN (MobilePhone)-3))),
MobilePhone
)
)
),
IF( ISPICKVAL (CountryISDCode__c, 'singapore'),
('+65' & MobilePhone),
IF( ISPICKVAL (CountryISDCode__c, 'india'),
('+91' & MobilePhone),
IF( ISPICKVAL (CountryISDCode__c, 'us'),
('+01' & MobilePhone),
MobilePhone
)
)
)
)
--
Abhi
All Answers
Post the code snippet. Show us what have you tried to do.
--
Abhi
set<String> CountryISDCode = new Set<String>();
set<id> accid=new Set<id>();
if(trigger.isInsert || trigger.isUpdate)
{
List<Contact> updateContact= new List<Contact>();
for(Contact con : Trigger.new)
{
if(con.CountryISDCode__c != null && con.MobilePhone != null &&con.MobilePhone.length() < 12)
{
if(con.CountryISDCode__c=='singapore')
{
con.MobilePhone = '+65'+ con.MobilePhone;
}
else if(con.CountryISDCode__c=='india')
{
con.MobilePhone ='+91'+ con.MobilePhone;
}
else if(con.CountryISDCode__c=='us')
{
con.MobilePhone ='+01'+ con.MobilePhone;
}
}
}
}
}
Here is what you need to do in a workflow:
OR (
NOT( ISPICKVAL(leadtherace__CountryISDCode__c, '')),
ISCHANGED(leadtherace__CountryISDCode__c)
),
NOT( ISBLANK (MobilePhone) )
- Now add a Field Update on Mobile field
- The formula would look like:
- IF( BEGINS( MobilePhone, '+'),
I have tested this. It works fine. Please let me know if you need clarification on anything I have mentioned. If you want trigger, please do the similar logic in the trigger code.IF( ISPICKVAL (CountryISDCode__c, 'singapore'),
('+65' & ( RIGHT (MobilePhone, LEN (MobilePhone)-3))),
IF( ISPICKVAL (CountryISDCode__c, 'india'),
('+91' & ( RIGHT (MobilePhone, LEN (MobilePhone)-3))),
IF( ISPICKVAL (CountryISDCode__c, 'us'),
('+01' & ( RIGHT (MobilePhone, LEN (MobilePhone)-3))),
MobilePhone
)
)
),
IF( ISPICKVAL (CountryISDCode__c, 'singapore'),
('+65' & MobilePhone),
IF( ISPICKVAL (CountryISDCode__c, 'india'),
('+91' & MobilePhone),
IF( ISPICKVAL (CountryISDCode__c, 'us'),
('+01' & MobilePhone),
MobilePhone
)
)
)
)
--
Abhi