You need to sign in to do that
Don't have an account?
Vasu.P
Trigger is not working while Updating through Dataloadeer
Hi All,
trigger UpdateActiveProspect on Opportunity (after insert,after update){
list<account> ali=new list<account>();
if(trigger.isafter && (trigger.isinsert || trigger.isupdate)){
list<Opportunity> Opp=new list<Opportunity>();
List<Opportunity> opp1=new List<Opportunity>();
set<id> ids=new set<id>();
for(Opportunity o:trigger.new){
ids.add(o.accountid);
}
list<account> accli=[select id,name,Account_Status__c,Active_Prospect__c ,(select id,accountID,StageName,Contract_Expiration_Date__c from Opportunities) from account where id=:ids];
for(account a1:accli){
for(Opportunity op:a1.opportunities){
if(op.stageName=='Intro Meeting / Discovery'||op.stageName=='Relationship Building'||
op.stageName=='Opportunity Identification'||op.stageName=='Solution/Submit RFI'||
op.stageName=='Solution/Submit RFP'||op.stageName=='Solution/Submit Pre-emptive Bid'||
op.stageName=='Presentation / Pitching'||op.stageName=='Red Zone / Awarded'){
opp.add(op);
}
if(op.stageName=='Win (Contract Signed)'&& op.Contract_Expiration_Date__c > System.TODAY()){
opp1.add(op);
}
}
if(opp.size()>0){
a1.Active_Prospect__c=true;
}else{
a1.Active_Prospect__c=false;
}
if(opp1.Size()>0){
a1.Account_Status__c='Active';
}else{
a1.Account_Status__c='Inactive';
}
ali.add(a1);
}
}
update ali;
}
Above is the Trigger. Any one can Help
Thanks In advance
trigger UpdateActiveProspect on Opportunity (after insert,after update){
list<account> ali=new list<account>();
if(trigger.isafter && (trigger.isinsert || trigger.isupdate)){
list<Opportunity> Opp=new list<Opportunity>();
List<Opportunity> opp1=new List<Opportunity>();
set<id> ids=new set<id>();
for(Opportunity o:trigger.new){
ids.add(o.accountid);
}
list<account> accli=[select id,name,Account_Status__c,Active_Prospect__c ,(select id,accountID,StageName,Contract_Expiration_Date__c from Opportunities) from account where id=:ids];
for(account a1:accli){
for(Opportunity op:a1.opportunities){
if(op.stageName=='Intro Meeting / Discovery'||op.stageName=='Relationship Building'||
op.stageName=='Opportunity Identification'||op.stageName=='Solution/Submit RFI'||
op.stageName=='Solution/Submit RFP'||op.stageName=='Solution/Submit Pre-emptive Bid'||
op.stageName=='Presentation / Pitching'||op.stageName=='Red Zone / Awarded'){
opp.add(op);
}
if(op.stageName=='Win (Contract Signed)'&& op.Contract_Expiration_Date__c > System.TODAY()){
opp1.add(op);
}
}
if(opp.size()>0){
a1.Active_Prospect__c=true;
}else{
a1.Active_Prospect__c=false;
}
if(opp1.Size()>0){
a1.Account_Status__c='Active';
}else{
a1.Account_Status__c='Inactive';
}
ali.add(a1);
}
}
update ali;
}
Above is the Trigger. Any one can Help
Thanks In advance
@Satya,
Please use this code and marked as best answer :)
Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com
All Answers
@Satya, Use this code and let me know the results :)
Thanks
Rajat maheshwari
rajatzmaheshwari@gmail.com
i have made some Change in the code ,
trigger UpdateActiveProspect on Opportunity (after insert,after update){
Map<Id,Account> mp_Account = new Map<Id,Account>();
List<Opportunity> opp1=new List<Opportunity>();
for(Opportunity op:trigger.new){
if(op.stageName=='Intro Meeting / Discovery'||op.stageName=='Relationship Building'||
op.stageName=='Opportunity Identification'||op.stageName=='Solution/Submit RFI'||
op.stageName=='Solution/Submit RFP'||op.stageName=='Solution/Submit Pre-emptive Bid'||
op.stageName=='Presentation / Pitching'||op.stageName=='Red Zone / Awarded'){
op.Account.Active_Prospect__c = true;
mp_Account.put(op.AccountId,op.Account);
}
else if(op.stageName=='Win (Contract Signed)'&& op.Contract_Expiration_Date__c > System.TODAY()){
op.Account.Account_Status__c='Active';
mp_Account.put(op.AccountId,op.Account);
}
else{
op.Account.Account_Status__c='';
}
}
if(mp_Account!=null && mp_Account.values()!=null)
update mp_Account.values();
}
when i tried to add an Opportunity it's giving the : caused by: System.NullPointerException: Attempt to de-reference a null object
Please Suggest!
Hi Satya,
Please give a try with that : -
trigger UpdateActiveProspect on Opportunity (after insert,after update){
Map<Id,Account> mp_Account = new Map<Id,Account>();
List<Opportunity> opp1=new List<Opportunity>();
for(Opportunity op:trigger.new){
if(op.stageName!=null)
{
if(op.stageName=='Intro Meeting / Discovery'||op.stageName=='Relationship Building'||
op.stageName=='Opportunity Identification'||op.stageName=='Solution/Submit RFI'||
op.stageName=='Solution/Submit RFP'||op.stageName=='Solution/Submit Pre-emptive Bid'||
op.stageName=='Presentation / Pitching'||op.stageName=='Red Zone / Awarded'){
op.Account.Active_Prospect__c = true;
mp_Account.put(op.AccountId,op.Account);
}
else if(op.stageName=='Win (Contract Signed)'&& op.Contract_Expiration_Date__c > System.TODAY()){
op.Account.Account_Status__c='Active';
mp_Account.put(op.AccountId,op.Account);
}
}
}
if(mp_Account!=null && mp_Account.values()!=null)
update mp_Account.values();
}
Let me know the line number, where it gives error.
Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com
@Satya,
Please use this code and marked as best answer :)
Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com
It's Working Fine