function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swathi CseSwathi Cse 

trigger webtolead

Hi,
Give me the sample code for web to lead scenario. When web to lead is saved it has to go for the perticular record for example lead government record type.

Thanks,
Swathi
Arunkumar RArunkumar R
Hi,

Please try the below sample code,
 
Trigger SetRecordToFixedRecordType on Lead(before insert)
{ 
    Id recId = Schema.getGlobalDescribe().get(Lead).getDescribe().getRecordTypeInfosByName().get(Lead - GOVT).getRecordTypeId(); 

    for(Lead led :Trigger.new)
    { 
        if((led.Status__c != null && led.Status__c='Submitted') && (led.Web_To_Lead__c != null &&     led.Web_To_Lead__c='Lead - GOVT'))
        { 
            led.RecordTypeId= recId; 
        } 
    }
}

 
Amit K AAmit K A
You do not require the code for it ,

Select fields to include on your Web-to-Lead form. Use the Add and Remove arrows to move fields between the Available Fields list and the Selected Fields list, and use the Up and Down arrows to change the order of the fields on your form.
For using lead record types, select the Lead Record Type field if you want users to select a record type for Web-generated leads.