You need to sign in to do that
Don't have an account?
Vin.
How to automatically incremente a number based on a specific record type
Hi,
I would like to automatically incremente a Number field for leads that are in a specific record type.
The only options I see is to create an assignment rule or a trigger that automatically incremente the number field only when a lead from the record type is created.
However, I don't know how to create a trigger or which assignment could make such thing. Can someone assist on this?
Thanks.
I would like to automatically incremente a Number field for leads that are in a specific record type.
The only options I see is to create an assignment rule or a trigger that automatically incremente the number field only when a lead from the record type is created.
However, I don't know how to create a trigger or which assignment could make such thing. Can someone assist on this?
Thanks.
Id recordTpId = Schema.SObjectType.Lead.getRecordTypeInfosByName().get('RecordTypeName').getRecordTypeId();
String query='SELECT COUNT() FROM Account WHERE RecordTypeId=\''+recordTpId+'\'';
Integer count=database.countQuery(query);
for(Lead ld:Trigger.new){
if(ld.RecordTypeId == recordTpId){
count++;
ld.Count__c=count;
}
}
}
Replace 'RecordTypeName,Count__c' by your record type name and custom field api name respectively.
It's not the best practice to write code like this. But, hope it will solve your problem.