Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

here is a piece of code if the number is less than 9.00 Below code is working properly but if i want the number between 9.00-5.00 i need to display same values in object__c then how to do that

if([0].Number__c <= 9.00 )
                    object__c obj = new object__c();
                        obj .place__c = 'london';
                        obj .Score__c = 2;
                    insert obj ; 
share|improve this question
Not clear..! What do u want to do if the number is between 9.00-5.00 ? – Avidev9 Dec 12 '12 at 13:27
even if the no is between 9-5 place & score should save with same records – rakesh Dec 12 '12 at 13:33
the trigger is on object__c right? and what are the events on the trigger? – Avidev9 Dec 12 '12 at 13:35
Just add &&[0].Number__c >= 5.00 to your if clause – Sergey Utko Dec 12 '12 at 13:39
up vote 2 down vote accepted

If you want to check whether the number is between 9.00-5.00 you can do like this

List<object__c > objList = new List<object__c >();
for(YourObject__c yourObj :{
    if(yourObj.Number__c <= 4.00  && yourObj.Number__c >= 1.00){
        object__c obj = new object__c();
        obj .place__c = 'usa';
        obj .Score__c = 4;
    else if(yourObj.Number__c <= 9.00  && yourObj.Number__c >= 5.00){
        object__c obj = new object__c();
        obj .place__c = 'london';
        obj .Score__c = 2;

Please note the code that you posted was not bulkified and will not be able to handle bulk records.

share|improve this answer
Thank you, but in another case between 4.00-1.00 need to save record as place = usa, score = 4 if between 5.00-9.00 need to save record as place = london, score = 2. how to go with this – rakesh Dec 12 '12 at 13:46
updated the answer to accommodate the same – Avidev9 Dec 12 '12 at 13:49
thank you Avidev, I have a doubt regarding this code we mentioned if less than 9.00 place = london and score = 2, if it less than 4-1 than it doent mean that it is less than 9 – rakesh Dec 12 '12 at 13:58
But this is the way how if else works. If the first condition is satisfied then second condition will never be evaluated.Why dont you try out the code and check the same? – Avidev9 Dec 12 '12 at 14:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.