Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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(trigger.new[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 && trigger.new[0].Number__c >= 5.00 to your if clause –  mast0r Dec 12 '12 at 13:39
add comment

1 Answer

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 : trigger.new){
    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;
        objList.add(yourObj);
    }
    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;
        objList.add(yourObj);
    }
}

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
add comment

Your Answer

 
discard

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.