How to get a proper output through trigger after insert salesforce?
I Created an object called Percentile with 10 fields and created one more field called Percentage. If I enter a value for one field and if I save it, Then the Percentage field value should be updated with 10 %. Same like that if I enter a value for two fields, Then the Percentage field value should be updated with 20 % and vice versa. I am not getting proper output. Please provide good logic. The trigger which i had used is given below.
trigger PercentageTrigger on Percentile__c (after insert) { Listpercent=[select Tilte__ c,Name,LastName__c,Email__c,Mobile_Number__c, Industry__c,Father_Name__c,Father_Phone_Number__c,Mother_Name__c,Mother_Phone_Number__c, Percentage__c from Percentile__c where ID IN:Trigger.NewMap.keySet()]; for(Percentile__c cent:percent){ f(cent.Name != Null){ cent.Percentage__c=10; update cent; } if(cent.Name != Null && cent.Tilte__c !=null){ cent.Percentage__c=20; update cent; } } }
Try this for triggers after inserting salesforce
trigger PercentageTrigger on Percentile__c (before insert) { for(Percentile__c cent: Trigger.New){ if(cent.Percentage__c < 0 xss=removed xss=removed xss=removed xss=removed xss=removed>
Here you don't need to do any DML operation to update data; and the if conditions need a single condition to check and increment % for that field share;