You need to sign in to do that
Don't have an account?
cml9
Something is wrong my Trigger during Update. Please help.
Hi Dev Masters,
I am writing a trigger wherein if there is a new Account created in SF it will create a Contact. The trigger was working fine during creation of new Contacts but during UPDATES its not doing anything. I am not sure why this is not working can anyone help? Thanks in advance!
I am writing a trigger wherein if there is a new Account created in SF it will create a Contact. The trigger was working fine during creation of new Contacts but during UPDATES its not doing anything. I am not sure why this is not working can anyone help? Thanks in advance!
trigger AccountSync on Account (after insert, after update) { if (trigger.isafter) { if (trigger.isInsert) { for (Account a: Trigger.new ) { if (a.RecordTypeId == '01228000000kgCd') { // Use to check if Record Type is equal to Sales Process if (a.CreatedById == '005p0000000r5oI') { //Use to determine if Account was created through API || Needs to be changed to '00528000004nP9f' before deploying to Prod Decimal myD = a.Business_ID__c; // Conversion of Double to Integer so that when converted to it will remove .00 Integer newInt = myD.intValue(); Contact c = New Contact(); c.LastName = a.Contact_Name__c.Substring(a.Contact_Name__c.indexof(' '),a.Contact_Name__c.length()); c.FirstName = a.Contact_Name__c.substring(0,a.Contact_Name__c.indexof(' ')); c.AccountId = a.id; c.Phone = a.Phone; c.Email= a.Contact_Email__c; c.Phone = a.Contact_Phone__c; c.Business_Id__c = newInt.format().remove(','); c.User_ID__c = a.User_Id__c; insert C; } } } } if (trigger.isUpdate) { for (Account a: Trigger.new ) { if (a.RecordTypeId == '01228000000kgCd') { // Use to check if Record Type is equal to Sales Process if (a.CreatedById == '005p0000000r5oI') { //Use to determine if Account was created through API || Needs to be changed to '00528000004nP9f' before deploying to Prod Decimal myD = a.Business_ID__c; // Conversion of Double to Integer so that when converted to it will remove .00 Integer newInt = myD.intValue(); Contact c = New Contact(); c.LastName = a.Contact_Name__c.Substring(a.Contact_Name__c.indexof(' '),a.Contact_Name__c.length()); c.FirstName = a.Contact_Name__c.substring(0,a.Contact_Name__c.indexof(' ')); c.Phone = a.Phone; c.Email= a.Contact_Email__c; c.Phone = a.Contact_Phone__c; update C; } } } } } }
use below updated code for insert and update as well.
Hope this will help you.
mark it best ANSWER if its work for you.
Thanks
karthik
Use below code,
Hope this will help you.
Thanks
karthik