You need to sign in to do that
Don't have an account?
Jennifer24w
List has more then 1 row for assignment to SObject
I'm hoping someone can help. We have a vendor that wrote this code for us (see below). I'm trying to run an Informatica task that updates some users records and this is the error I'm getting.
Error loading into target [Contact] : Error received from salesforce.com. Fields []. Status code [CANNOT_MODIFY_MANAGED_OBJECT]. Message [addToCList: execution of AfterUpdatecaused by: System.QueryException: List has more than 1 row for assignment to SObject()].
I am updating 14 contact records but keep getting a failure and this message is what it's telling me. But I don't understand what the problem is that is causing this message. Hopefully someone can help me understand what is happening here. I'm not a developer but I do understand what is written in the code, I just don't know why it's giving me this partiuclar error. TIA for any assistance.
Apex Code
Error loading into target [Contact] : Error received from salesforce.com. Fields []. Status code [CANNOT_MODIFY_MANAGED_OBJECT]. Message [addToCList: execution of AfterUpdatecaused by: System.QueryException: List has more than 1 row for assignment to SObject()].
I am updating 14 contact records but keep getting a failure and this message is what it's telling me. But I don't understand what the problem is that is causing this message. Hopefully someone can help me understand what is happening here. I'm not a developer but I do understand what is written in the code, I just don't know why it's giving me this partiuclar error. TIA for any assistance.
Apex Code
trigger addToCList on Contact (after update) {
for (Contact cont : Trigger.New)
{
if (cont.Jenzabar_ID__c !=null)
{
if (cont.TargetX_SRMb__Student_Type__c=='First-Time Freshman'||cont.TargetX_SRMb__Student_Type__c=='International Freshman')
{
if (cont.TargetX_SRMb__Status__c=='Deposit Paid')
{
addAllAttachments.getAttachmentsForStudent(cont.X18_digit_ID__c,cont.Jenzabar_ID__c);
}
} else
{
if (cont.TargetX_SRMb__Status__c=='Accept')
{
addAllAttachments.getAttachmentsForStudent(cont.X18_digit_ID__c,cont.Jenzabar_ID__c);
for (Contact cont : Trigger.New)
{
if (cont.Jenzabar_ID__c !=null)
{
if (cont.TargetX_SRMb__Student_Type__c=='First-Time Freshman'||cont.TargetX_SRMb__Student_Type__c=='International Freshman')
{
if (cont.TargetX_SRMb__Status__c=='Deposit Paid')
{
addAllAttachments.getAttachmentsForStudent(cont.X18_digit_ID__c,cont.Jenzabar_ID__c);
}
} else
{
if (cont.TargetX_SRMb__Status__c=='Accept')
{
addAllAttachments.getAttachmentsForStudent(cont.X18_digit_ID__c,cont.Jenzabar_ID__c);
I think the above the trigger is not bulkified. in the following method, we are passing only one contact record.
But Informatica task at a time updating more than one contact.
We need to bulkify the above trigger and class.
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
Salesforce Freelance Consultant/Developer/Administrator/Trainer
@For Salesforce Project Support: varaprasad4sfdc@gmail.com
Salesforce latest interview questions and training videos :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
.
You cannt able to update the same record in after update so you need to use before update as shown below