You need to sign in to do that
Don't have an account?
Sana123
How can i do insert, update and delete with if and else condition for checking everything for insert,update and delete.
#trigger code
trigger AccountTrigger1 on Account (after insert ) {
if(trigger.isAfter && trigger.isInsert){
AccountTriggerHandler1.accountDetails(trigger.new);
}
}
#triggerhandlercode
public without sharing class AccountTriggerHandler1 {
public static void accountDetails(list<Account> lstAccount)
{
list<Contact> lstContact = new list<Contact>();
// list<Account> lstAccount = new list<Account>();
set<Id> setAccountIds = new set<Id>();
for(account acc : lstAccount){
setAccountIds.add(acc.Id);
}
if(setAccountIds.size() > 0){
for(account acc : [SELECT Id , Name ,Contacts__c From Account Where Id In : setAccountIds]){
List<String> listofcon = acc.Contacts__c.split('\r\n');
for(String con : listofcon){
Contact con1 = new Contact();
con1.firstname = con.substringBetween('=',',');
con1.LastName =con.substringBetween('=',',');
con1.MobilePhone = con.substringBetween('=',',');
con1.Email = con.substringAfter('Email=').substringBefore(',');
con1.AccountId = acc.Id;
lstContact.add(con1);
}
}
if(lstContact.size() > 0){
insert lstContact;
}
}
}
}
#please help me in this i am newbie to salesforce
trigger AccountTrigger1 on Account (after insert ) {
if(trigger.isAfter && trigger.isInsert){
AccountTriggerHandler1.accountDetails(trigger.new);
}
}
#triggerhandlercode
public without sharing class AccountTriggerHandler1 {
public static void accountDetails(list<Account> lstAccount)
{
list<Contact> lstContact = new list<Contact>();
// list<Account> lstAccount = new list<Account>();
set<Id> setAccountIds = new set<Id>();
for(account acc : lstAccount){
setAccountIds.add(acc.Id);
}
if(setAccountIds.size() > 0){
for(account acc : [SELECT Id , Name ,Contacts__c From Account Where Id In : setAccountIds]){
List<String> listofcon = acc.Contacts__c.split('\r\n');
for(String con : listofcon){
Contact con1 = new Contact();
con1.firstname = con.substringBetween('=',',');
con1.LastName =con.substringBetween('=',',');
con1.MobilePhone = con.substringBetween('=',',');
con1.Email = con.substringAfter('Email=').substringBefore(',');
con1.AccountId = acc.Id;
lstContact.add(con1);
}
}
if(lstContact.size() > 0){
insert lstContact;
}
}
}
}
#please help me in this i am newbie to salesforce
Hi,
Please check the below code.
Thank You