You need to sign in to do that
Don't have an account?
msb-appsupport1.3905906418879758E12
How to stop SF convert a lead to a contact when I assign a campaign to the lead using code?
When I insert a lead, I want to assign a campaign to the lead. However, after I do it, the SF will convert the lead to a contact automatically. How could I solve this using Apex code or Visualforce?
The code I use is as following:
Map<String,Id> recordtypeMap = new Map<String,Id>();
for(RecordType leadRT : [select id, Name from RecordType where SObjectType = 'Lead' ]){
recordtypeMap.put(leadRT.Name,leadRT.Id);
}
Lead l = new Lead(firstname='testInsertLead-1-0326', lastname='test-1-0326',company='Temp Company',
RecordTypeId = recordtypeMap.get('Temp Lead Type'));
insert l;
Campaign c = [Select id from Campaign limit 1];
CampaignMember mem = new CampaignMember (campaignid=c.id, leadid=l.id);
insert mem;
Thanks.
The code I use is as following:
Map<String,Id> recordtypeMap = new Map<String,Id>();
for(RecordType leadRT : [select id, Name from RecordType where SObjectType = 'Lead' ]){
recordtypeMap.put(leadRT.Name,leadRT.Id);
}
Lead l = new Lead(firstname='testInsertLead-1-0326', lastname='test-1-0326',company='Temp Company',
RecordTypeId = recordtypeMap.get('Temp Lead Type'));
insert l;
Campaign c = [Select id from Campaign limit 1];
CampaignMember mem = new CampaignMember (campaignid=c.id, leadid=l.id);
insert mem;
Thanks.
Apex code will do the trick,
Put the code in the If block - if the condition is satisfied only then the code will execute.
Else throw an exception and an Error.
Try and check if the Query is working fine and returning the exact results.
Regards,
Ashish
This will not be a accurate one but you can flag a lead which you are creating by code like " In Campaign " and write a trigger on contact to delete the respective contact if created by a Campaign lead on After Insert