-----PUNTO 1-------------
trigger trigger_opp1 on Opportunity (before update) {
account A = new account(name = 'Before Update');
insert A;
for (opportunity o: trigger.new)
{
o.accountid = a.id;
}
system.debug('record inserito');
}
-------------------------------------------------------------
trigger trigger_opp2 on Opportunity (after update) {
account A = new account(name = 'after Update');
insert A;
list <opportunity> appoggio = [select id, accountid from opportunity where id in: trigger.new];
list <opportunity> app = new list<opportunity> ();
for (opportunity o: appoggio)
{
if(o.accountid == NULL)
{
o.accountid = a.id;
app.add(o);
}
}
update app;
system.debug('record inserito');
}
-------------------------------------------------------------
----PUNTO 2--------------------------------------------
trigger trigger_opp3 on Opportunity (before insert) {
account A = new account(name = 'Before insert');
insert A;
for (opportunity o: trigger.new)
{
o.accountid = a.id;
}
system.debug('record inserito');
}
-------------------------------------------------------
trigger trigger_opp4 on Opportunity (after insert) {
account A = new account (name = 'after insert');
insert A;
list<opportunity> appoggio = [select id, accountid from opportunity where id in: trigger.new];
for(opportunity o: appoggio)
{
o.accountid = a.id;
}
update appoggio;
}
-------------------------------------------------------
----PUNTO 3--------------------------
trigger trigger_opp5 on Opportunity (before update) {
opportunity O = new opportunity(name = 'before update', stagename = 'Closed Won', closedate = system.today());
insert O;
}
---------------------------------------------------------
trigger trigger_opp6 on Opportunity (after update) {
opportunity O = new opportunity(name = 'after update', stagename = 'Closed loss', closedate = system.today()+2);
insert O;
}
--------------------------------------------------------