You need to sign in to do that
Don't have an account?
Shubham Sengar
trigger Oppsame on Contact(After insert) {
List <Opportunity> Opp = new List <Opportunity>();
For (Contact C: Trigger.new){
Opportunity O = new Opportunity();
O.Name = C.Name;
O.CloseDate = System.TODAY();
O.StageName = 'Closed Won';
O.AccountId = C.id;
Opp.add(O);
}
Insert Opp;
}
when we insert contact there will a insert a Opportunity for this contact
its give insert time errror ..
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Oppsame caused an unexpected exception, contact your administrator: Oppsame: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Account ID: id value of incorrect type: 00328000005GxcuAAC: [AccountId]: Trigger.Oppsame: line 18, column 1
trigger problem 3
trigger Oppsame on Contact(After insert) {
List <Opportunity> Opp = new List <Opportunity>();
For (Contact C: Trigger.new){
Opportunity O = new Opportunity();
O.Name = C.Name;
O.CloseDate = System.TODAY();
O.StageName = 'Closed Won';
O.AccountId = C.id;
Opp.add(O);
}
Insert Opp;
}
when we insert contact there will a insert a Opportunity for this contact
its give insert time errror ..
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Oppsame caused an unexpected exception, contact your administrator: Oppsame: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Account ID: id value of incorrect type: 00328000005GxcuAAC: [AccountId]: Trigger.Oppsame: line 18, column 1
Modify trigger like this..
trigger Oppsame on Contact(After insert) {
List <Opportunity> Opp = new List <Opportunity>();
For (Contact C: Trigger.new){
Opportunity O = new Opportunity();
O.Name = C.Name;
O.CloseDate = System.TODAY();
O.StageName = 'Closed Won';
O.AccountId = C.Accountid;
Opp.add(O);
}
Insert Opp;
}
All Answers
O.AccountId = C.id;
to
O.AccountId = C.Accountid;
Modify trigger like this..
trigger Oppsame on Contact(After insert) {
List <Opportunity> Opp = new List <Opportunity>();
For (Contact C: Trigger.new){
Opportunity O = new Opportunity();
O.Name = C.Name;
O.CloseDate = System.TODAY();
O.StageName = 'Closed Won';
O.AccountId = C.Accountid;
Opp.add(O);
}
Insert Opp;
}
still its giving error
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Oppsame caused an unexpected exception, contact your administrator: Oppsame: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Opportunity Name]: [Opportunity Name]: Trigger.Oppsame: line 18, column 1
trigger Oppsame on Contact(After insert) {
List <Opportunity> Opp = new List <Opportunity>();
For (Contact C: Trigger.new){
Opportunity O = new Opportunity();
O.Name = C.Name;
O.CloseDate = System.TODAY();
O.StageName = 'Closed Won';
O.AccountId = C.Accountid;
Opp.add(O);
}
Insert Opp;
}
O.Name = C.Name;
to this:
O.Name = C.LastName;
Thx
trigger Oppsame on Contact(After insert) {
List <Opportunity> Opp = new List <Opportunity>();
For (Contact C: Trigger.new){
Opportunity O = new Opportunity();
O.Name = C.LastName;
O.CloseDate = System.TODAY();
O.StageName = 'Closed Won';
O.AccountId = C.Accountid;
Opp.add(O);
}
Insert Opp;
}
Do this:
1)Check to make sure you don't have an validation rules on the opportunity object that stop the trigger from being successful.
Disable all validation rules on the opportunity if you have too.
2) When checking the opportunity (after creating a contact), make sure to use "New this week" filter list to get the newly created opportunities.
Thx
Do you have custom required fields for opportunities or work flow/process builder causing issues?'
Thx
ya here no any custom required fields for opportunities or work flow/process
i think in this line
O.AccountId = C.Accountid;
some thing is worng may be ??
bcoz u r using contact object then y we use accountid