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
softwarensoftwaren 

URGENTTT...please help me

hi.İm new on apex and i have a project.İ designed a custom object which name is order__c.İts works like opportunity.İ want to make it working syncronised with opportunity.When i create an order record it an be add on opportunity as same name and same properties(ordername,account,close date,) i fixed it no problem.But also i need to do these too.When i add an order line item(related to product) on order it can be added the same time on opportunity line item on the record which is in same name.Also i need to update the opportunity record which is created from order.Could you help me please???

Cloud CredenceCloud Credence

Hi,

 

You need to write a trigger on Order Object, with after insert, after update events, and inserts records into Opportunity. 

 

Please make sure you handle bulk inserts/updates.

 

Best Wishes,

softwarensoftwaren

Could you check my codes?This is my code to add a new opportunity when a new order has been added (im using a few common fields)

public class OrderToOppHandler {

public void onAfterInsert(List<order__c> OrderList){
Set<ID>Ids = new Set<ID>();
List<Opportunity> oppList = new List<Opportunity>();
for(Order__c ordl: OrderList)
{
Ids.add(ordl.ID);
oppList.add(new Opportunity(Name=ordl.Name ,AccountID=ordl.Account__c, StageName=ordl.Stage__c,Amount=ordl.Total_Amount__c,CloseDate=ordl.CloseDate__c));
}

insert oppList;


}

*****************

also i want to add,delete and update events for opportunity line items which is created by on order.When i create,delete or update an order line item then the operation must be on the opportunity object and opportunity line item too.İ want to do this and this is code.But its not working help me please.

 

public with sharing class OrderItemToOpp {

public void onBeforeUpdate(List<Opportunity> OppList){
List<OpportunityLineItem> OppLineList = new List <OpportunityLineItem> {};

OppLinelist .add(new OpportunityLineItem
(Opportunity = Trigger.new.Order__c,
ServiceDate = Trigger.new.Date__c,
UnitPrice = Trigger.new.Sales_Price__c,
Product2 = Trigger.new.Product__c,(i got this error here 'Save error: Invalid field Product for SObject OpportunityLineItem')
Quantity = Trigger.new.Quantity__c));
}
insert OppLineList;
}

*****

could you write me a class for an update.Maybe then i can advance it.