You need to sign in to do that
Don't have an account?
Rupeshk67
Wanted to know about Split function and its uses
Hi Guys,
I am trying to write a trigger on below reuirements and stuck at one point(how to add a word in between last name of a contact record once it is created).
Reuirements:
Write a trigger on Account object.
Criteria:-
On Creation of account record, it should create one associated Contact record whenever above criteria meet.
Example :- “Telestra Contact Rupesh”
Please note: word 'contact' should come in middle of account name
Thanks,
Rupesh
I am trying to write a trigger on below reuirements and stuck at one point(how to add a word in between last name of a contact record once it is created).
Reuirements:
Write a trigger on Account object.
Criteria:-
- Type:- “Customer”
- Account Name end with “Your Name” . Example , “Telestra Rupesh”
On Creation of account record, it should create one associated Contact record whenever above criteria meet.
Example :- “Telestra Contact Rupesh”
Please note: word 'contact' should come in middle of account name
Thanks,
Rupesh
You can take reference from the below code and you can use substringBefore and substringAfter method.
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
All Answers
class:
public class AccountTriggerHandler {
public static void createContacts(List<Account> acclist){
list<Contact> conList= new list<Contact>();
for(Account a:acclist){
Contact con = new Contact();
if(a.Name.endsWith('rupesh') && a.Type.Contains('Customer')){
con.LastName = a.name.substring(a.Name.indexOf(''))+ ' Contact';
con.AccountId = a.Id;
conList.add(con);
}
}
if(conList!=null){
insert conList;
}
}
}
it adds 'contact' at last but not in middle of contact name. Please help me to resolve it.
Thanks,
You can take reference from the below code and you can use substringBefore and substringAfter method.
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
Thanks for your help, it is working as expected.
Regards,
Rupesh
I think this is the good way.
let me know if it helps you by marking it as best answer.
Thank you
when i use above code it works only when account name is like 'test rupesh'.
If i mention account name as ' test techbook comp rupesh' then contact name appears as 'test contact techbook' and other words disappear.
Kinldy help.
Thanks !