You need to sign in to do that
Don't have an account?
Arpit Gupta 37
after update trigger
Error: Compile Error: Invalid identifier ' '. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_', or unicode characters from U+0080 to U+FFFE. at line 20 column 20
Objective:
To update account Field when an opportunity stage name is Closed won.This will happen when an opportunity is inserted and updated to Stagename: Closed won.
Below is the code
trigger updatecontact on opportunity (after insert,after update) {
map<id,opportunity> Mp=new map<id,opportunity>();
/*([select id,accountid from opportunity where stagename='Closed Won' and (id in : Trigger.new or id in: Trigger.oldMap.keySet())]);*/
for(opportunity Opp:Trigger.new)
{
if(Trigger.isUpdate)
{
if((Opp.stagename = 'Closed Won') && ((Trigger.oldMap.get(Opp.Id).stagename)!='Closed Won'))
{
Mp.put(Opp.id,Opp.accountid);
}
}
if(Trigger.isInsert)
{
if(Opp.stagename == 'Closed Won')
{
Mp.put(Opp.id,Opp.accountid);
}
}
}
set<Id> S= new set<Id>();
for(opportunity Op: Mp.values())
{
S.add(Op.accountid);
}
List<Account> Ac= [select Id,type from account where id in:S];
for(account Acc: Ac)
{
Acc.type='Customer - Direct';
}
Update Ac;
}
Objective:
To update account Field when an opportunity stage name is Closed won.This will happen when an opportunity is inserted and updated to Stagename: Closed won.
Below is the code
trigger updatecontact on opportunity (after insert,after update) {
map<id,opportunity> Mp=new map<id,opportunity>();
/*([select id,accountid from opportunity where stagename='Closed Won' and (id in : Trigger.new or id in: Trigger.oldMap.keySet())]);*/
for(opportunity Opp:Trigger.new)
{
if(Trigger.isUpdate)
{
if((Opp.stagename = 'Closed Won') && ((Trigger.oldMap.get(Opp.Id).stagename)!='Closed Won'))
{
Mp.put(Opp.id,Opp.accountid);
}
}
if(Trigger.isInsert)
{
if(Opp.stagename == 'Closed Won')
{
Mp.put(Opp.id,Opp.accountid);
}
}
}
set<Id> S= new set<Id>();
for(opportunity Op: Mp.values())
{
S.add(Op.accountid);
}
List<Account> Ac= [select Id,type from account where id in:S];
for(account Acc: Ac)
{
Acc.type='Customer - Direct';
}
Update Ac;
}
Please use below modified code and let me know ifit helps you.
-----------------------
trigger updatecontact on opportunity(after insert, after update) {
map < id, id > Mp = new map < id, id > ();
/*([select id,accountid from opportunity where stagename='Closed Won' and (id in : Trigger.new or id in: Trigger.oldMap.keySet())]);*/
for (opportunity Opp: Trigger.new) {
if (Trigger.isUpdate) {
if ((Opp.stagename == 'Closed Won') && ((Trigger.oldMap.get(Opp.Id).stagename) != 'Closed Won')) {
Mp.put(Opp.id, Opp.accountid);
}
}
if (Trigger.isInsert) {
if (Opp.stagename == 'Closed Won') {
Mp.put(Opp.id, Opp.accountid);
}
}
}
set < Id > S = new set < Id > ();
for (Id accountId: Mp.values()) {
S.add(accountId);
}
List < Account > Ac = [select Id, type from account where id in : S];
for (account Acc: Ac) {
Acc.type = 'Customer - Direct';
}
Update Ac;
}
Regards,
Pawan Kumar