You need to sign in to do that
Don't have an account?
sdjagdja wdguqwe
I have created same fields for both contact object and opportunity object. I would like to automatically update the field values on opportunity object whenever I cretae new customer record.
I'm new to Apex and creating Triggers so hoping someone can help. Here's the scenario;
I have created same fields for both contact object and opportunity object. I would like to automatically update the field values on opportunity object whenever I cretae new customer record.
For this I have written the trigger with the event after insert. But I am getting error
Can anyone correct the below code plz….
trigger updateField on Contact (after insert) {
Set<Id> Ids= new Set<Id>();
for (Contact contact : Trigger.new)
{
Ids.add(customer.Id);
}
List<Contact> contactList = new List<Contact>([Select Id,First_name__c, Last_name_c FromContact where Id in :Ids]);
for(Contact temp : contactList )
{
Oppertunities oppor = new Oppertunities();
oppor.First_Name__c = temp. First_name__c,;
oppor.Last_Name_c = Last_name_c;
insert oppor;
}
I have created same fields for both contact object and opportunity object. I would like to automatically update the field values on opportunity object whenever I cretae new customer record.
For this I have written the trigger with the event after insert. But I am getting error
Can anyone correct the below code plz….
trigger updateField on Contact (after insert) {
Set<Id> Ids= new Set<Id>();
for (Contact contact : Trigger.new)
{
Ids.add(customer.Id);
}
List<Contact> contactList = new List<Contact>([Select Id,First_name__c, Last_name_c FromContact where Id in :Ids]);
for(Contact temp : contactList )
{
Oppertunities oppor = new Oppertunities();
oppor.First_Name__c = temp. First_name__c,;
oppor.Last_Name_c = Last_name_c;
insert oppor;
}
The below trigger is to autoppulate the field values from contact to opportunity.
Suppose if i change any field value in Opportunity object that should update in Opportunity as well as in Contact also.
So for this i need to proceed with event after Update. Can you please guide me how to proceed further
trigger ConOpp on Contact(after insert) {
List<Opportunity> newOpps = new List<Opportunity>();
for (Contact con : Trigger.new) {
Opportunity opp = new Opportunity();
opp.Name = con.LastName+' Opportunity';
opp.StageName = 'Prospecting';
opp.Status__c = con.Status__c;
opp.version__c = con.version__c;
opp.CloseDate = Date.today() + 90;
// opp.AccountId = acc.Id; // Use the trigger record's ID
newOpps.add(opp);
}
if(newOpps.size()>0)
insert newOpps;
}