You need to sign in to do that
Don't have an account?
anas mendili
trigger AccountTrigger on Account (before insert) {
if(trigger.isInsert && trigger.isBefore){
AccountTriggerHandler.AppendAccountName(trigger.new);
}
}
this is the trigger
and this is the handler class I am stuck on
public class AccountTriggerHandler {
public static void AppendAccountName(List<Account> newAccountList){
---------------------------------
I am thinking of smth like this but don't know how to code it write I am very new to apex
if{ recordtypeid.name==customer account
then account a =[SELECT Customer_Name FROM account LIMIT 1];
a.Customer_Name = a.Name +'-Customer';
update a;
a.Partner_Name = a.Name +'-Customer';
update a;
Account.Customer_name= Account.name +'-Customer'
else Account.Partner_name= account.name +'-Partner'
}
How append text depending on type of reccord using triggers and trigger handler
Anytime a new Customer account is created, and the Account Name is filled, the Customer
The name should be filled with the same name as the account Name, appended with “- Customer”
- E.g.: Customer Account
- Account Name: Recruitment
- Customer Name: Recruitment – Customer
Similarly, every time a new partner account is created, the partner name should be Account
Name appended with “- Partner”
o Eg: Partner Account
o Account Name: Salesforce
o Partner Name Salesforce – Partner
Using triggers in apex I should am trying to do that but I don't know how to write the logic I have in mind which is to get the record type and then check if it is a Customer_Account or Partner_Account depending on that either append '-Customer' or '-Partner' as text in the respective name fieldtrigger AccountTrigger on Account (before insert) {
if(trigger.isInsert && trigger.isBefore){
AccountTriggerHandler.AppendAccountName(trigger.new);
}
}
this is the trigger
and this is the handler class I am stuck on
public class AccountTriggerHandler {
public static void AppendAccountName(List<Account> newAccountList){
---------------------------------
I am thinking of smth like this but don't know how to code it write I am very new to apex
if{ recordtypeid.name==customer account
then account a =[SELECT Customer_Name FROM account LIMIT 1];
a.Customer_Name = a.Name +'-Customer';
update a;
a.Partner_Name = a.Name +'-Customer';
update a;
Account.Customer_name= Account.name +'-Customer'
else Account.Partner_name= account.name +'-Partner'
}
The way you are appending is correct, but just do this little change :-
Kindly mark it as the best answer if it works.
Thanks,
Priya Ranjan
Try this