function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
June PowerJune Power 

Need Trigger to create opportunity once custom Account field is populated

Ramesh KallooriRamesh Kalloori
trigger insertOpp on Account(After insert)
{
Opportunity op=new Opportunity();
op.Name='Google';
op.CloseDate=date.today().format();
op.StageName='Qualification';
insert op;
}
let me know if you have any clarifications.

thanks,
RAmesh
Ramu_SFDCRamu_SFDC
+1 Ramesh Kallori's code

You need to put an if condition so that this trigger fires only when a particular Account custom field is populated something as below

trigger insertOpp on Account(After insert)
{
List<Opportunity> opplist=new List<Opportunity>();
for(Account acc:Trigger.new){
if(acc.<custom field name>!=null && acc.<custom field name>==''){
Opportunity op=new Opportunity();
op.Name='Google';
op.CloseDate=date.today().format();
op.StageName='Qualification';
opplist.add(op);
}
}
insert opplist;
}


June PowerJune Power
trigger insertOpp on Account(After insert)
{
List<Opportunity> opplist=new List<Opportunity>();
for(Account acc:Trigger.new){
if(acc.Property_Address_from_Survey__c!=null && acc.Property_Address_from_Survey__c==''){
Opportunity op=new Opportunity();
op.Name=acc.Property_Address_from_Survey__c;
op.CloseDate=date.today().format();
op.StageName='Pre-Qual';
opplist.add(op);
}
}
insert opplist;
}
June PowerJune Power
I got this error: required (...)+ loop did not match anything at input 'trigger'

Can you help?

trigger insertOpp on Account(After insert)
{
List<Opportunity> opplist=new List<Opportunity>();
for(Account acc:Trigger.new){
if(acc.Property_Address_from_Survey__c!=null && acc.Property_Address_from_Survey__c==''){
Opportunity op=new Opportunity();
op.Name=acc.Property_Address_from_Survey__c;
op.CloseDate=date.today().format();
op.StageName='Pre-Qual';
opplist.add(op);
}
}
insert opplist;
}
Ramesh KallooriRamesh Kalloori
Hi Ami,

op.Stagename='Pre-Qual'

Stagename does not have the value Pre-Qual please add the picklit value in Opportunity object.

or try the below.

trigger insertOpp on Account(After insert)
{
List<Opportunity> opplist=new List<Opportunity>();
for(Account acc:Trigger.new){
if(acc.Property_Address_from_Survey__c!=null && acc.Property_Address_from_Survey__c==''){
Opportunity op=new Opportunity();
op.Name=acc.Property_Address_from_Survey__c;
op.CloseDate=date.today().format();
op.StageName='Qualification';
opplist.add(op);
}
}
insert opplist;
}
thanks,
Ramesh

June PowerJune Power
I'm still getting the same error. Here's my picklist. I also tried Prospect [image: Inline image 1]