You need to sign in to do that
Don't have an account?
Vikram Singh 157
Hi ! All , add the related opportunity for each new or updated account if no opportunity is already associated with the account.(Name fOr opportunity 1,2,3,4 and stage name prospecting and close date should be one month ahead of current date.
This will work fine but unable to add opp by name 1, 2, 3, 4...
trigger CreateRelatedRec on Account (after insert, after update) {
List<Opportunity> opplist = new List<Opportunity>();
List<Account> Acc = [Select ID , Name from Account where Id in : trigger.new AND Id NOT in
(select accountid from Opportunity)];
for(account a : Acc){
opplist.add(New Opportunity(Name=a.Name +'opportunity',StageName='Prospecting',
CloseDate=Date.today()+30,AccountId=a.Id));
}
If(oppList.Size()>0){
upsert opplist;
}
}
trigger CreateRelatedRec on Account (after insert, after update) {
List<Opportunity> opplist = new List<Opportunity>();
List<Account> Acc = [Select ID , Name from Account where Id in : trigger.new AND Id NOT in
(select accountid from Opportunity)];
for(account a : Acc){
opplist.add(New Opportunity(Name=a.Name +'opportunity',StageName='Prospecting',
CloseDate=Date.today()+30,AccountId=a.Id));
}
If(oppList.Size()>0){
upsert opplist;
}
}
I have tested this trigger and it is working fine. Below is the output it would give. Trigger would only work as AFTER INSERT and not after update etc..
Final Output:
Trigger Code:
Hope it helps and if it solves the query then please mark it as best answer!
All Answers
I think I can help you here but I am not understanding the requirement.
and name should be start for opportunity with 1,2,3,4 .. like this and stage name should be 'prospecting'and close date should be one month ahead of current date.
Everything was working fine but i am unable to create opprtunity with the name 1,2,3..
Is this the requirement?
If yes, then what happens when user updates the same Account (Acme, INC.) next day? should it create a 4 more opportunities? OR this auto creation should happen only at the first time.
Thank You!
This auto creation should be happen only first time .
I have tested this trigger and it is working fine. Below is the output it would give. Trigger would only work as AFTER INSERT and not after update etc..
Final Output:
Trigger Code:
Hope it helps and if it solves the query then please mark it as best answer!