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
sdjagdja wdguqwesdjagdja wdguqwe 

I have created same fields for Customer and oppertunity object.When i create a new record for customer that fields values should update in Oppertunity also.

I have created same fields for Customer and oppertunity object.When i create a new record for customer that fields values should update in Oppertunity also.For this i have written a trigger between these two objectwith the event after insert, But i am getting error.
Please correct the below code if it is wrong.
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,SMETS_Meter_version__c,Meter_Status__c  FromContact where Id in :Ids]);    
       for(Contact temp : contactList )
       {
       Oppertunities oppor = new  Oppertunities();
       oppor.SMETS_Meter_version__c = temp.SMETS_Meter_version__c;
       oppor.Meter_Status__c = temp.Meter_Status__c;
       insert oppor;
       }
     }
Vinoth Vijaya BaskerVinoth Vijaya Basker
Hello,

Can you please post the error message that you received? 

Thanks,
Vinoth
Vinoth Vijaya BaskerVinoth Vijaya Basker
It seems that there is no space between From and Contact in Query that you are using. Please give a space between From and Contact. 

Please use the below statement which is updated,
List<Contact> contactList = new List<Contact>([Select Id, SMETS_Meter_version__c, Meter_Status__c  From Contact where Id in :Ids]);

Thanks,
Vinoth
Vinoth Vijaya BaskerVinoth Vijaya Basker
Please Use 'Opportunity' instead of 'Oppertunities'.
 
Opportunity oppor = new  Opportunity();


 
sdjagdja wdguqwesdjagdja wdguqwe
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  From Contact where Id in :Ids]);   
       for(Contact temp : contactList )
       {
       Opportunity oppor = new  Opportunity ();
       oppor. First_Name__c c = temp. First_Name__c, __c;
       oppor. Last_Name_c = temp. Last_Name_c;
       insert oppor;
I have done the modifications still it is showing the error as  Error: Compile Error: Variable does not exist: customer.Id at line 5 column 13
Vinoth Vijaya BaskerVinoth Vijaya Basker
Please replace existing code(For block) to add Contact ids in list with the below code, 


for (Contact con : Trigger.new)
{
    Ids.add(con.Id);  
 }



 
sdjagdja wdguqwesdjagdja wdguqwe
Error: Compile Error: expecting a semi-colon, found 'Order_Number__c' at line 11 column 34
Vinoth Vijaya BaskerVinoth Vijaya Basker
I could not find Order_Number__c in the code that you posted in the description. 

Can you please post the recent code. 

Thanks,
Vinoth
sdjagdja wdguqwesdjagdja wdguqwe
Just i have changed the names.

trigger updateField on Contact (after insert) {
 Set<Id> Ids= new Set<Id>();
    for (Contact con : Trigger.new)
    {
    Ids.add(con.Id);  
    }
  List<Contact> contactList = new List<Contact>([Select Id,Order_Number__c, Amount_c  From Contact where Id in :Ids]);   
       for(Contact temp : contactList )
       {
       Opportunity oppor = new  Opportunity ();
       oppor. Order_Number __c = temp. Order_Number __c;
       oppor. Amount_c = temp. Amount_c;
       insert oppor;
       }
 
Vinoth Vijaya BaskerVinoth Vijaya Basker
oppor. Order_Number __c = temp. Order_Number __c;
oppor. Amount_c = temp. Amount_c;

/*In the above two statements, there is a space between oppor. and Order_Number __c. 
And, oppor. and Amount_c. */

Please replace the above two statements with the below code, 

oppor.Order_Number __c = temp.Order_Number __c;
oppor.Amount_c = temp.Amount_c;