You need to sign in to do that
Don't have an account?
Kiril Vodenicharov 7
This is a trigger which populates a custom Key Fields. If the trigger had at least 3 Lead key fields it will create a Task.
Need help to wirte Unit Test over popuplated Lead fields.
trigger PopulateKeyFieldCount on Lead (after insert) { Integer countOfKeyFields = 0; Set<String> keyFields = new Set<String>{'FirstName', 'LastName', 'Email', 'Phone', 'Website', 'Title'}; String fieldsWithTest = ''; List<Task> taskList = new List<Task>(); for(Lead leadRecord : Trigger.New) { countOfKeyFields = 0; if(leadRecord.Key_Fields_Populated_c__c != null) { countOfKeyFields = leadRecord.FirstName != null ? countOfKeyFields + 1: countOfKeyFields; countOfKeyFields = leadRecord.LastName != null ? countOfKeyFields + 1: countOfKeyFields; countOfKeyFields = leadRecord.Email != null ? countOfKeyFields + 1: countOfKeyFields; } if(countOfKeyFields == 3) { for(String fieldName : keyFields) { Task task = new Task ( Subject = 'Verify the ' + fieldName, Priority = 'Hight', Status = 'Complete', Type = 'Action', ownerId = leadRecord.OwnerId ); taskList.add(task); } } } if(taskList != null && !taskList.isEmpty()) { insert taskList; } }
This is a trigger which populates a custom Key Fields. If the trigger had at least 3 Lead key fields it will create a Task.
Hi Kiril,
If the data type of Key_Fields_Populated_c__c field is Number then check this test class:-
All Answers
Please check this test class:-
Please Mark it as Best Answer if it helps.
Thanks
It says "Illiegal assignment from String to Decimal." in your code sample.
Also I'm useing a Pattern down bellow in the code. It will be cool if you help me to finish it.
What is the type of Key_Fields_Populated_c__c field?
Hi Kiril,
If the data type of Key_Fields_Populated_c__c field is Number then check this test class:-