You need to sign in to do that
Don't have an account?
Vennila
Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, No selected contact: Contact ID: [ContactId].
Hi ,
Please help me to resolve this below issue. its urgent.
I want to create case, after the lead is created from marketo.
For this, i wrote a trigger in after insert for lead.
The lead is successfully created from marketo. but the case is not created.
It is displaying this exception,Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, No selected contact: Contact ID: [ContactId].
But the same trigger is working fine and creating case for manually creating a lead and creating a lead through visualforce page.
And also, If i hardcoded the contactid in the trigger, its creating a case successfully. But Contact id is not a required field for case.
The only thing,it is not working for lead came from Maketo.
Thanks in Advance!
Please help me to resolve this below issue. its urgent.
I want to create case, after the lead is created from marketo.
For this, i wrote a trigger in after insert for lead.
The lead is successfully created from marketo. but the case is not created.
It is displaying this exception,Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, No selected contact: Contact ID: [ContactId].
But the same trigger is working fine and creating case for manually creating a lead and creating a lead through visualforce page.
And also, If i hardcoded the contactid in the trigger, its creating a case successfully. But Contact id is not a required field for case.
The only thing,it is not working for lead came from Maketo.
Thanks in Advance!
This is the code for creating a case. here i am using trigger handler class.
Trigger
---------
trigger CaseCreationfromRFI on Lead (after insert,after update)
{
public String caseRecordType = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('Case - Support').getRecordTypeId();
List<case> newcaselist = new List<case>();
List<Lead> LeadList = new List<Lead>();
RFICaseTriggerHandler_ac handler=new RFICaseTriggerHandler_ac();
for(lead l: trigger.new)
{
LeadList.add(l);
}
handler.casecreationmethod(LeadList);
}
Trigger Handler Class
------------------------------
Public without sharing class RFICaseTriggerHandler_ac
{
public List<Case> newcaselist=new List<case>();
public String caseRecordType = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('Case - Support').getRecordTypeId();
public Case newcase=new case();
String RecTypId=String.valueOf(caseRecordType);
Map<String,string> mapCaseCustSettingReferenceObject = new Map<String,string>();
List<User> u=new List<User>();
public string leadid;
Map<String,ProfileList__c> profiledetails=new Map<String,ProfileList__c>();
public RFICaseTriggerHandler_ac()
{
profiledetails=ProfileList__c.getAll();
List<Webform_Picklist__c> webformpicklist=[select Picklist_Value__c,Case_Name__c from Webform_Picklist__c];
for(Webform_Picklist__c lstval:webformpicklist)
{
mapCaseCustSettingReferenceObject.put(lstval.Picklist_Value__c,lstval.Case_Name__c);
}
}
public void casecreationmethod(List<Lead> leadlst)
{
System.debug('---------------->'+leadlst);
String s;
String marketouserid = profiledetails.get('Marketo User').ProfileId__c;
String webuserid = profiledetails.get('Site User').ProfileId__c ;
for(Lead l:leadlst)
{
/* This code using for creating a case, Which lead is came from marketo. Here i am hardcoded the contactid, so it is working fine. but i don't want contact id in my functionality. If i removed contactid , it is throwing an exception like FIELD INTEGRITY EXCEPTION, NO SELECTED CONTACT ID like this. */
if((l.createdbyid == marketouserid || l.LastModifiedByid==marketouserid ) && l.IsConverted ==false)
{
newcase.Lead__c=l.id;//commented on Mar 10, 2014
newcase.ownerid=marketouserid ;
newcase.ContactID='003c0000000osIv';
newcase.RecordTypeId=caseRecordType;
newcase.Origin='Web';
newcase.subject=l.Reason_For_Contact__c;
newcase.RFI_Reason_For_Conact__c=newCase.Subject;
newcase.RFI_Prefered_Method_of_Contact__c=l.Preferred_Mode_of_Contact__c ;
if(mapCaseCustSettingReferenceObject.get(l.Reason_For_Contact__c) != null)
newcase.case_Name__c = mapCaseCustSettingReferenceObject.get(l.Reason_For_Contact__c);
else
{
if(l.Preferred_Mode_of_Contact__c == 'Phone')
newcase.case_name__c= 'Call Applicant/Student';
else
newcase.case_name__c = 'Email Applicant/Student';
}
newCase.Description = l.Description;
newcaselist.add(newcase);
}
/* this code is creating case which is created from visualforce page, here i am not using contact id, its working fine. its not thowing an any exception */
else if((l.createdbyid == webuserid || l.LastModifiedByid==webuserid) && l.IsConverted ==false)
{
newcase.Lead__c=l.id;//commented on Mar 10, 2014
newcase.ownerid=webuserid;
newcase.RecordTypeId=caseRecordType;
newcase.Origin='West.edu';
newcase.subject=l.Reason_For_Contact__c;
newcase.RFI_Reason_For_Conact__c=newCase.Subject;
newcase.RFI_Prefered_Method_of_Contact__c=l.Preferred_Mode_of_Contact__c ;
if(mapCaseCustSettingReferenceObject.get(l.Reason_For_Contact__c) != null)
newcase.case_Name__c = mapCaseCustSettingReferenceObject.get(l.Reason_For_Contact__c);
else
{
if(l.Preferred_Mode_of_Contact__c == 'Phone')
newcase.case_name__c= 'Call Applicant/Student';
else
newcase.case_name__c = 'Email Applicant/Student';
}
newCase.Description = l.Description;
newcaselist.add(newcase);
}
}
try{
if(!TriggerHelperClass.hadRFICasecreationfrmlead())
{
if(newcaselist.size() > 0)
{
insert newcaselist;
}
TriggerHelperClass.setRFICasecreationfrmlead();
}
}
catch(Exception e)
{
System.Debug('exception+============'+e.getmessage());
System.Debug('Stacktrace:' + e.getStackTraceString());
}
}
}