You need to sign in to do that
Don't have an account?
Rahul63
Can any one please help as below code is not working for multiple records at a time. Our scenario is to update the Opportunity stage based on Opportunity Building and Quote creation. If those doesn't have then we need to throw the error.
public void beforeUpdate( ) {
List<Opportunity> oppLst = Trigger.old;
List < Opportunity > newOptyList = Trigger.New;
List < Quote > QuoteList = [SELECT Id, Name, Opportunity.name FROM Quote where OpportunityID = : oppLst[0].Id];
List < Opportunity_Building__c > buildingopportunityList = new List < Opportunity_Building__c > ([SELECT Opportunity__c,Id, Name FROM Opportunity_Building__c where Opportunity__c = : oppLst[0].Id]);
for(Opportunity oppNew :newOptyList ) {
for(opportunity oppOld: oppLst){
if ((buildingopportunityList.size() == 0 )){
if(oppOld.StageName == 'Prospecting' && oppNew.StageName == 'Cost analysis' ) {
oppNew.StageName.addError(Label.Opp_Stage_CostAnalysis_Error_without_OppBldg);
}
}
if ((QuoteList.size() == 0)){
if(oppOld.StageName == 'Cost analysis' && oppNew.StageName == 'Offer negotiation'){
oppNew.StageName.addError(Label.Opp_Stage_Offernegotiation_Error_without_Quote);
}
}
List<Opportunity> oppLst = Trigger.old;
List < Opportunity > newOptyList = Trigger.New;
List < Quote > QuoteList = [SELECT Id, Name, Opportunity.name FROM Quote where OpportunityID = : oppLst[0].Id];
List < Opportunity_Building__c > buildingopportunityList = new List < Opportunity_Building__c > ([SELECT Opportunity__c,Id, Name FROM Opportunity_Building__c where Opportunity__c = : oppLst[0].Id]);
for(Opportunity oppNew :newOptyList ) {
for(opportunity oppOld: oppLst){
if ((buildingopportunityList.size() == 0 )){
if(oppOld.StageName == 'Prospecting' && oppNew.StageName == 'Cost analysis' ) {
oppNew.StageName.addError(Label.Opp_Stage_CostAnalysis_Error_without_OppBldg);
}
}
if ((QuoteList.size() == 0)){
if(oppOld.StageName == 'Cost analysis' && oppNew.StageName == 'Offer negotiation'){
oppNew.StageName.addError(Label.Opp_Stage_Offernegotiation_Error_without_Quote);
}
}
Rahul63
Above code was working as expected but code needs to remodified to work for multiple records. Can you please help me. Thanks in Advance
Wilfredo Morillo 20
Wilfredo Morillo 20
This should be in a trigger not in a class.