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 

Webtolead trigger

Hi,
Trigger SetRecordToFixedRecordType on Lead(before insert)

    Id recId=recordTypeId('Lead','Lead - GOVT'); 

    for(Lead led :Trigger.new)

    { 
    if(led.Status__c='Submitted' && led.Web_To_Lead__c='Lead - GOVT')
        { 
            led.RecordTypeId='012280000005fr1'; 
        } 
    }
 Public static Id recordTypeId(string Lead,string GOVT)

    Id recTypeId; 
    if(Lead!= null && Lead - GOVT != null)
    { 
    recTypeId= Schema.getGlobalDescribe().get(Lead).getDescribe().getRecordTypeInfosByName().get(Lead - GOVT).getRecordTypeId();
    }
     return recTypeId; 
    } 

}


This is the trigger written for web to lead .when the webtolead is saved it has to to perticular record type but i am getting error.

Thanks,
swathi.
logontokartiklogontokartik
Hi Swathi, when you are posting code and asking for question in developer forums, please make sure you format the code properly and answer a specific question, if you want someone to do the work for you, you can find someone on AppExchange or on recruiting website.

Coming to your question, the following line doesn't make sense.
if(Lead!= null && Lead - GOVT != null)
Please fix the line to use the right attribute, maybe something like
if(Lead!= null && GOVT != null)




 
Tarun_KhandelwalTarun_Khandelwal
Hi Swathi,

Use following code -
Trigger SetRecordToFixedRecordType on Lead(before insert)
{ 
    Id recId=recordTypeId('Lead','Lead - GOVT'); 
    for(Lead led :Trigger.new) { 
		if(led.Status__c='Submitted' && led.Web_To_Lead__c='Lead - GOVT'){ 
            led.RecordTypeId='012280000005fr1'; 
        } 
    }
	
	Public static Id recordTypeId(string Lead,string GOVT) { 
		Id recTypeId; 
		if(Lead != null && GOVT != null) { 
			recTypeId= Schema.getGlobalDescribe().get(Lead).getDescribe().getRecordTypeInfosByName().get(GOVT).getRecordTypeId();
		}
		return recTypeId; 
	} 
}

You are using String value of string as variable. And might be it is giving error. Let me know in case of any query.
Amit K AAmit K A
Use string functions when u  compare any string value