You need to sign in to do that
Don't have an account?

Want to add more than one record at time
Hi,
i want to add 100 records to opportunit and 100 records to opportunityrole
Here is my code
With this code i got the following exception.

Please let me know the best way how to fix this.
Thanks in advance
i want to add 100 records to opportunit and 100 records to opportunityrole
Here is my code
for (Integer i = 1; i <= 100; i++) { opportunity = null; role = null; opportunity = new Opportunity(); role = new OpportunityContactRole(); opportunity.name = account.name + ' Donation (' + i + ' of 5) ' + current_date; opportunity.Donation_Type__c = contact.Donation_Type__c; opportunity.Payment_Type__c = payment_type; opportunity.amount = Integer.valueof(contact.Donataion_Amount__c); opportunity.CloseDate = re_today_date; opportunity.stageName = 'Pledged'; oppList.add(opportunity); insert opportunity; // Then create opportunity role role.opportunityId = opportunity.id; if(is_anonymous == false) { role.contactId = contact.id; } else { role.contactId = prev_contact_id; } role.Role = '10'; insert role; }
With this code i got the following exception.
Please let me know the best way how to fix this.
Thanks in advance
I'm wondering how I couldn't see that.
You cannot compare ID and String.
Try to replace this line
with this
All Answers
Don't forget about bulkification. https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
I have used the same code as below
Now getting the following exception
Please help me.
Very thanks in advance.
role.opportunityId = opp.id;
Do we need to add triggers?
Denis can you please help me more i am new to SalesForce
Thanks in advance.
Are you sure that this line is correct?
Role is picklist value.It should be look like 'Decision Maker' or 'Business User'
What type have prev_contact_id variable ?
Yes the line is correct
and prev_contact_id variable has contact id having type String
I am splitting it in two or three replies
Thanks
1) Ensure that Contact with ID = 003M000000TiQ3A exists.
2) Try to use 18-digit Id(as you use for prev_account_id)
Tell me if this will help.
https://emea.salesforce.com/003M000000TiQ3A
instead of EMEA you should set you server.
1) Contact with ID = 003M000000TiQ3A exists.
2) I have used 18 digit
Still not succeeded
same exception
Please help me
I'm wondering how I couldn't see that.
You cannot compare ID and String.
Try to replace this line
with this