• Jeetesh Bahuguna
  • 0 Points
  • Member since 2012

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 2
I am getting this error while using vf component attribute for passing custom setting name, however i am not getting any error if I am hard coding values instead of component attribute, and it is showing me other custom settings field value.  

I have a requirement to automatically convert a Lead if the Lead status is a specific value (the Lead is to be converted when Lead.Status = 'Complete Request - Convert'). I wrote an insert/update trigger that performs the conversion process. It seems to be working fine when I test it by creating a Lead thru the Salesforce UI. If I create it with the specified status value, it is immediately converted upon saving my new record. So, I then wrote a unit test to test it programmatically. My unit test code looks like this:



	// Tests successful conversion of a single Lead inserted directly in the 'Complete Request - Convert' status
public static testMethod void testSingleInsert() {

RecordType clientLeadRT = [SELECT Id FROM RecordType WHERE DeveloperName = 'Client' AND SObjectType = 'Lead'];

Lead l = new Lead();
l.FirstName = 'Test';
l.LastName = 'Lead1';
l.Company = 'Test Company';
l.Phone = '3335552233';
l.Email = 'tlead1@test.com';
l.Status = 'Complete Request - Convert';
l.Street = '123 Test Street';
l.City = 'Test Town';
l.State = 'TN';
l.PostalCode = '12345';
l.RecordTypeId = clientLeadRT.Id;
insert l;

// Retrieve the Lead... it should have been converted
Lead convertedLead = [SELECT Id, IsConverted, ConvertedContactId, ConvertedAccountId, Status FROM Lead WHERE Id = :l.Id];
System.assertEquals('Qualified', convertedLead.Status);

// Retrieve the converted Contact
Contact convertedContact = [SELECT Id, FirstName, LastName, CompanyName__c, AccountId, RecordType.Name,
Phone, Email, MailingStreet, MailingCity, MailingState, MailingPostalCode
FROM Contact WHERE Id = :convertedLead.ConvertedContactId];
System.assertEquals(l.FirstName, convertedContact.FirstName);
System.assertEquals(l.LastName, convertedContact.LastName);
System.assertEquals(l.Company, convertedContact.CompanyName__c);
System.assertEquals(convertedLead.ConvertedAccountId, convertedContact.AccountId);
System.assertEquals(l.Phone, convertedContact.Phone);
System.assertEquals(l.Street, convertedContact.MailingStreet);
System.assertEquals(l.City, convertedContact.MailingCity);
System.assertEquals(l.State, convertedContact.MailingState);
System.assertEquals(l.PostalCode, convertedContact.MailingPostalCode);
System.assertEquals('Client', convertedContact.RecordType.Name);



The status value 'Complete Request - Convert' is the value that triggers the auto-conversion. When I run this test, I get an exception at the "insert l;" statement (highlighted in red). The error is:


System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: []


I get the same error if I try to create a Lead in this state from the "Execute Anonymous" window.


If I create the Lead in a different state, and then update it to "Complete Request - Convert", it works fine. Is there any workaround for this, or can I not insert a Lead that is converted by a trigger in the same transaction?

  • August 05, 2010
  • Like
  • 0

Record type unavailable Cannot find default record type of the appropriate type.


I am seeing this error when trying to Convert a lead. I have checked the profile for the current user, and the default record types are both Contacts and Accounts are accessible. (I have selected Do Not Create Opportunity, though there are no opportunity record types).


The docs were no help at all, no results in Google for the error. Does anyone know what the solution is?