function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
atharva Vispute 3atharva Vispute 3 

Help me to find the solution

Hi,

problem statement is
in currency if the amount is in  10,000-20,000 then picklist value must be cold, if amount is in 20,000-50,000 then picklist value must be hot and if the amount is more than 50,000 then value should be warm. So what kind of trigger i have to use here?? Plzz help me to find solution.

Thanks!!
Best Answer chosen by atharva Vispute 3
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

I have updated the meaning of each line in the below.
 
trigger ProjectRating on Project__c (before insert,before update) {
//Above line shows that this trigger need to be fired in create and update scenerio
    
    for(Project__c pro:Trigger.new){//iterating over the record
        Project__c oldpro = new Project__c();//Initialisng project to store old value in case of update
        if(Trigger.isupdate)// As we have Trigger.oldmap only in update scenerio so checking f it is update or not and then assiging old value of project
        {
            oldpro= trigger.oldmap.get(pro.id);
        }
            if(Trigger.isinsert || (Trigger.isupdate && pro.amount__c!=oldpro.Amount__c)){
                // Below lines are our logic based on Amount values we are assiging the rating field
                if(pro.Amount__c>10000 && pro.Amount__c <=20000)
                    pro.Rating__c='cold';
                if(pro.Amount__c>20000 && pro.Amount__c <=50000)
                 pro.Rating__c='hot';
                if(pro.Amount__c>50000 )
                 pro.Rating__c='warm';
            }
    }

}

If this solution helps, Please mark it as best answer so it helps others.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

Are the fields on Account object?

Thanks
atharva Vispute 3atharva Vispute 3
Hi Praveen,

Amount field has currency data type and it is project object. and also that picklist field in project object. So how to write that trigger code??
Thanks!!
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

Can ypou try the below code.
 
trigger ProjectRating on Project__c (before insert,before update) {
    
    for(Project__c pro:Trigger.new){
        Project__c oldpro = new Project__c();
        if(Trigger.isupdate)
        {
            oldpro= trigger.oldmap.get(pro.id);
        }
            if(Trigger.isinsert || (Trigger.isupdate && pro.amount__c!=oldpro.Amount__c)){
                
                if(pro.Amount__c>10000 && pro.Amount__c <=20000)
                    pro.Rating__c='cold';
                if(pro.Amount__c>20000 && pro.Amount__c <=50000)
                 pro.Rating__c='hot';
                if(pro.Amount__c>50000 )
                 pro.Rating__c='warm';
            }
    }

}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
atharva Vispute 3atharva Vispute 3
Hi Praveen,

It's Working.. Thank you very much. Can you please provide me explanation about this code?

Thanks!!
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

I have updated the meaning of each line in the below.
 
trigger ProjectRating on Project__c (before insert,before update) {
//Above line shows that this trigger need to be fired in create and update scenerio
    
    for(Project__c pro:Trigger.new){//iterating over the record
        Project__c oldpro = new Project__c();//Initialisng project to store old value in case of update
        if(Trigger.isupdate)// As we have Trigger.oldmap only in update scenerio so checking f it is update or not and then assiging old value of project
        {
            oldpro= trigger.oldmap.get(pro.id);
        }
            if(Trigger.isinsert || (Trigger.isupdate && pro.amount__c!=oldpro.Amount__c)){
                // Below lines are our logic based on Amount values we are assiging the rating field
                if(pro.Amount__c>10000 && pro.Amount__c <=20000)
                    pro.Rating__c='cold';
                if(pro.Amount__c>20000 && pro.Amount__c <=50000)
                 pro.Rating__c='hot';
                if(pro.Amount__c>50000 )
                 pro.Rating__c='warm';
            }
    }

}

If this solution helps, Please mark it as best answer so it helps others.

Thanks,
This was selected as the best answer
atharva Vispute 3atharva Vispute 3
Hi Praveen,

Can you provide me this code in batch apex form??

Thanks!!
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

As this question need another implementation can you post it as other question so I can take it up. Just to make the question clear if other refers it.

Thanks,