On field lead source of opportunity object, if currently there are 4 records for the value 'Web', and the user tries to create or update an existing record the trigger should throw an error stating that there can not be more than 4 records for the value web. Till now i have got this
set<ID> userIdset = new set<ID>();
set<string> stageName = new set <string> ();
List<Opportunity> stageList = new List <Opportunity> ();
if (Trigger.isInsert)
{
Schema.DescribeFieldResult fieldResult = Opportunity.stageName.getdescribe();
List<schema.PicklistEntry> schemaPickList = fieldResult.getPickListvalues();
System.debug('Schema picklist'+schemaPicklist);
System.debug('stageList'+'\t'+stageList);
for (Opportunity o1 : Trigger.new)
{
}
}
if (Trigger.isUpdate)
{
for (Opportunity o2:trigger.new)
{
if (o2.stageName != Trigger.oldMap.get(o2.Id).stageName)
{
System.debug('Update trigger fired');
system.debug('The old status was'+Trigger.oldMap.get(o2.Id).stageName);
userIdset.add(o2.Id);
}
}
}
count()
query.