function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
venkata someswara rao vejjuvenkata someswara rao vejju 

update contact using trigger on conntact object

Hi all,

I have contact trigger like

trigger contacttrigger on Contact (before insert){
for(Contact c:Trigger.new)
{
if(exist)
{
//update contact
}
else
{
//creating contact and account
}
}
}
i am using external form for inserting contact records when ever a record is inserted inside contact object it fires the trigger . if already contact is exist i am updating contact that's fine at the same time new contact is created.I want to prevent that new contct creation if contact is already exist i am taking as email is unique.

Please suggest me.

Thank you
manasa chudamanimanasa chudamani
Hi venkata someswara rao vejju,

Please find the below link.Which is already solved in forum.

Best Regards,
Manasa.
https://developer.salesforce.com/forums/?id=906F0000000AzlvIAC
 
venkata someswara rao vejjuvenkata someswara rao vejju
hi manasa,

Thank You for your suggestion.But my question is once email is exist next time onwards it needs to update,above link shows like verifying email is exist or not.

here my sample code

trigger contacttrigger on Contact (before insert){
for(Contact c:Trigger.new)
{
if(email is exist)
{
//I want to update that contact here
Contact con=[select Id,firstname,lastnam from contact WHERE Email=:email];
con.firstname='salesforce';
update con;

}

}
}
upto here is fine but again it creates a new contact  after completion of trigger becuse every insertion i am firing trigger so that is my issue can you please suggest .

Thank You