Skip to main content
Hi I have built a trigger to throw error if a field is blank upon certain condition.

 

Since it is for large number of country i used trigger instead of validation rule.

 

However I tried to test it but the trigger did not throw the error.

 

Please find the trigger below

 

 

trigger TR_REMA_OPP on Opportunity (before insert,before update) {

for(Opportunity opps : trigger.new){

if((opps.AccountHQCountry__c != 'ARGENTINA' || opps.AccountHQCountry__c != 'AUSTRALIA' || opps.AccountHQCountry__c != 'AUSTRIA' || opps.AccountHQCountry__c != 'BELGIUM' || opps.AccountHQCountry__c != 'BRAZIL' || opps.AccountHQCountry__c != 'CANADA' || opps.AccountHQCountry__c != 'CHINA'

|| opps.AccountHQCountry__c != 'DENMARK' ||

opps.AccountHQCountry__c != 'FRANCE' ||

opps.AccountHQCountry__c != 'GERMANY' ||

opps.AccountHQCountry__c != 'HONG KONG' ||

opps.AccountHQCountry__c != 'INDIA' ||

opps.AccountHQCountry__c != 'INDONESIA' ||

opps.AccountHQCountry__c != 'IRELAND' ||

opps.AccountHQCountry__c != 'IRLAND' ||

opps.AccountHQCountry__c != 'ITALIA' ||

opps.AccountHQCountry__c != 'ITALY' ||

opps.AccountHQCountry__c != 'JAPAN' ||

opps.AccountHQCountry__c != 'KOREA (NORTH)' ||

opps.AccountHQCountry__c != 'KOREA (SOUTH)' ||

opps.AccountHQCountry__c != 'LAOS' ||

opps.AccountHQCountry__c != 'LUXEMBOURG' ||

opps.AccountHQCountry__c != 'MEXICO' ||

opps.AccountHQCountry__c != 'NETHERLANDS' ||

opps.AccountHQCountry__c != 'NEW CALEDONIA' ||

opps.AccountHQCountry__c != 'NEW ZEALAND' ||

opps.AccountHQCountry__c != 'NICARAGUA' ||

opps.AccountHQCountry__c != 'NORWAY' ||

opps.AccountHQCountry__c != 'PARAGUAY' ||

opps.AccountHQCountry__c != 'PERU' ||

opps.AccountHQCountry__c != 'PHILIPPINES' ||

opps.AccountHQCountry__c != 'POLAND' ||

opps.AccountHQCountry__c != 'PORTUGAL' ||

opps.AccountHQCountry__c != 'REPUBLIC OF SAN MARINO' ||

opps.AccountHQCountry__c != 'REUNION ISLAND' ||

opps.AccountHQCountry__c != 'SINGAPORE' ||

opps.AccountHQCountry__c != 'SPAIN' ||

opps.AccountHQCountry__c != 'SWEDEN' ||

opps.AccountHQCountry__c != 'SWITZERLAND' ||

opps.AccountHQCountry__c != 'UNITED KINGDOM' ||

opps.AccountHQCountry__c != 'UNITED STATES OF AMERICA' ||

opps.AccountHQCountry__c != 'URUGUAY' ||

opps.AccountHQCountry__c != 'VENEZUELA' ||

opps.AccountHQCountry__c !='VIETNAM' ||

opps.AccountHQCountry__c != 'ZIMBABWE') && opps.Probability >= 75 && opps.Financed__c == ''){

opps.addError('Financed is mandatory to update');

}

}

}

 

On the last step I also tried qpps.Financed__c.addError('this field is mandatory to update');

 

Stll did not worked.

 

opps.AccountHQCountry__c is a formula text field which will display the accounts country. Based upon the condition i set the account country to a different country to make sure the condition are met and the probability to above 75 still did not worked.

 

Please advise.

 

Thanks.
2 Antworten
  1. 13. Apr. 2020, 18:19
    Hi Samuel,

     

    Try this,

    trigger TR_REMA_OPP on Opportunity (before insert,before update) {

    for(Opportunity opps : trigger.new){

    if((opps.AccountHQCountry__c != 'ARGENTINA' || opps.AccountHQCountry__c != 'AUSTRALIA' || opps.AccountHQCountry__c != 'AUSTRIA' || opps.AccountHQCountry__c != 'BELGIUM' || opps.AccountHQCountry__c != 'BRAZIL' || opps.AccountHQCountry__c != 'CANADA' || opps.AccountHQCountry__c != 'CHINA'

    || opps.AccountHQCountry__c != 'DENMARK' ||

    opps.AccountHQCountry__c != 'FRANCE' ||

    opps.AccountHQCountry__c != 'GERMANY' ||

    opps.AccountHQCountry__c != 'HONG KONG' ||

    opps.AccountHQCountry__c != 'INDIA' ||

    opps.AccountHQCountry__c != 'INDONESIA' ||

    opps.AccountHQCountry__c != 'IRELAND' ||

    opps.AccountHQCountry__c != 'IRLAND' ||

    opps.AccountHQCountry__c != 'ITALIA' ||

    opps.AccountHQCountry__c != 'ITALY' ||

    opps.AccountHQCountry__c != 'JAPAN' ||

    opps.AccountHQCountry__c != 'KOREA (NORTH)' ||

    opps.AccountHQCountry__c != 'KOREA (SOUTH)' ||

    opps.AccountHQCountry__c != 'LAOS' ||

    opps.AccountHQCountry__c != 'LUXEMBOURG' ||

    opps.AccountHQCountry__c != 'MEXICO' ||

    opps.AccountHQCountry__c != 'NETHERLANDS' ||

    opps.AccountHQCountry__c != 'NEW CALEDONIA' ||

    opps.AccountHQCountry__c != 'NEW ZEALAND' ||

    opps.AccountHQCountry__c != 'NICARAGUA' ||

    opps.AccountHQCountry__c != 'NORWAY' ||

    opps.AccountHQCountry__c != 'PARAGUAY' ||

    opps.AccountHQCountry__c != 'PERU' ||

    opps.AccountHQCountry__c != 'PHILIPPINES' ||

    opps.AccountHQCountry__c != 'POLAND' ||

    opps.AccountHQCountry__c != 'PORTUGAL' ||

    opps.AccountHQCountry__c != 'REPUBLIC OF SAN MARINO' ||

    opps.AccountHQCountry__c != 'REUNION ISLAND' ||

    opps.AccountHQCountry__c != 'SINGAPORE' ||

    opps.AccountHQCountry__c != 'SPAIN' ||

    opps.AccountHQCountry__c != 'SWEDEN' ||

    opps.AccountHQCountry__c != 'SWITZERLAND' ||

    opps.AccountHQCountry__c != 'UNITED KINGDOM' ||

    opps.AccountHQCountry__c != 'UNITED STATES OF AMERICA' ||

    opps.AccountHQCountry__c != 'URUGUAY' ||

    opps.AccountHQCountry__c != 'VENEZUELA' ||

    opps.AccountHQCountry__c !='VIETNAM' ||

    opps.AccountHQCountry__c != 'ZIMBABWE') && opps.Probability >= 75 && opps.Financed__c = ''){

    opps.addError('Financed is mandatory to update');

    }

    }

    }

     

    Cheers!
0/9000