You need to sign in to do that
Don't have an account?

I want to update opportunityline item object based on status of opportunity i e closed Won
Here is my code Any help is appreciated
trigger Testopp on Opportunity (after insert, after update) {
for(Opportunity opp:Trigger.new){
if(opp.StageName=='Closed Won'){
OpportunityLineItem op=new OpportunityLineItem();
op.Demo5__Ready_to_close__c = true;
}
}
}
trigger Testopp on Opportunity (after insert, after update) {
for(Opportunity opp:Trigger.new){
if(opp.StageName=='Closed Won'){
OpportunityLineItem op=new OpportunityLineItem();
op.Demo5__Ready_to_close__c = true;
}
}
}
Let us know if this will help you
All Answers
As you have written a trigger on after update event so for this you have to explicit write a DML Insert or update to get it work.
Because in after event the auto DML Phase will not available so update your trigger like below.
Add the line Insert op;
op.Demo5__Ready_toclose__c = true;
insert op;
let me know if this helps you
Lokesh
Apex trigger Demo5.Testopp caused an unexpected exception, contact your administrator: Demo5.Testopp: execution of BeforeInsert caused by: System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Opportunity, Quantity]: [Opportunity, Quantity]: Trigger.Demo5.Testopp: line 10, column 1
Let us know if this will help you
I wrote a trigger for updating contact Phone, Title based on Account Ownership == 'Private' (picklist) and Phone, AccountNumber
if(Account Ownership == 'Private')
contact Phone = account phone
contact Title = account AccountNumber ...But i am getting error Can anyone explain me the Solution. Just Learning and Practicing based on someones scenarios ...Thank you
Code: trigger updateFieldsOnContact on Account (after insert, after update)
{
set<id> setAccid = new set<id>();
for(Account acc:trigger.new){
if(acc.Ownership =='Private' && acc.AccountNumber != Null && acc.Phone !=Null){
setAccid.add(acc.Id);
}
}
if(setAccid.size()>0)
{
map<id, account> mapAccCons = new map<id, account>([select id, (select id, Phone, Title from Contacts) from Account where id in :setAccid]);
list<Contact> cons = new List<Contact>();
for(account acc:trigger.new)
{
if(acc.Ownership == 'Private' && mapAccCons.containsKey(acc.Id).Contacts)
{
List<Contact> newUpdatingCons = mapAccCons.get(acc.Id).Contacts;
for(Contact cont : newUpdatingCons){
cont.Phone = acc.Phone;
cont.Title = acc.AccountNumber;
cons.add(cont);
}
}
}
if(cons.size()>0){
update cons;
}
}
}