You need to sign in to do that
Don't have an account?
edoardo_spano
Opportunity Probability doesn't work
Hi all,
I have a custom object with Opportunity as parent object.
When a new record of this custom object is created, a trigger updates the Stage of the opportunity, but the Probability doesn't updated.
Example:
These are the Opportunity's Stages:
- Stage1 (10%)
- Stage2 (30%)
- Stage3 (70%)
- Stage4 (100%)
The opportunity "OPP1" now is in "Stage2" and has Probability=30%. After inserting the record "CO1" as child record of "OPP1", the stage of "OPP1" is updated in "Stage3", but its Probability is still 30%.
Someone can explain to me the reason of this behavior.
Thanks in advance.
I have a custom object with Opportunity as parent object.
When a new record of this custom object is created, a trigger updates the Stage of the opportunity, but the Probability doesn't updated.
Example:
These are the Opportunity's Stages:
- Stage1 (10%)
- Stage2 (30%)
- Stage3 (70%)
- Stage4 (100%)
The opportunity "OPP1" now is in "Stage2" and has Probability=30%. After inserting the record "CO1" as child record of "OPP1", the stage of "OPP1" is updated in "Stage3", but its Probability is still 30%.
Someone can explain to me the reason of this behavior.
Thanks in advance.
Map<String, OpportunityStage> stageMap = new Map<String, OpportunityStage>();
for(OpportunityStage oStage : [select MasterLabel,DefaultProbability from OpportunityStage where isActive = true]){
stageMap.put(MasterLabel,DefaultProbability);
}
Schema.RecordTypeInfo rt = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('3 - Development');
Opportunity project = [SELECT Name, StageName, RecordTypeId, Collection__c
FROM Opportunity
WHERE Id = :off.OpportunityId];
if(project.StageName != 'Open Order' && project.StageName != 'Won'){
project.StageName = 'Open Development';
project.RecordTypeId = rt.getRecordTypeId();
project.probability = stageMap.get(project.StageName);
}
project.Collection__c = off.Collection_def__c;
update project;
All Answers
Map<String, OpportunityStage> stageMap = new Map<String, OpportunityStage>();
for(OpportunityStage oStage : [select MasterLabel,DefaultProbability from OpportunityStage where isActive = true]){
stageMap.put(MasterLabel,DefaultProbability);
}
Schema.RecordTypeInfo rt = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('3 - Development');
Opportunity project = [SELECT Name, StageName, RecordTypeId, Collection__c
FROM Opportunity
WHERE Id = :off.OpportunityId];
if(project.StageName != 'Open Order' && project.StageName != 'Won'){
project.StageName = 'Open Development';
project.RecordTypeId = rt.getRecordTypeId();
project.probability = stageMap.get(project.StageName);
}
project.Collection__c = off.Collection_def__c;
update project;