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
Sunil Kumar 545Sunil Kumar 545 

In account object .account site is there if i give (www.a.com)it should come like(www.anna.com)by using before insert trigger .

Best Answer chosen by Sunil Kumar 545
Jithesh VasudevanJithesh Vasudevan
Hi Sunil,

Ok. Then, you can give the condition like this,
 if(a.Site!='') in the trigger.



Validation rule:
If you want to use validation rule, you can use the below formula for Site field,

IF( Site <> 'www.anna.com',true,false)

This means if the site value is not 'www.anna.com' then it should throw an error. It will only save one value and that is 'www.anna.com'.

You can give an error message and give instructions to the user to choose the site as 'www.anna.com'.

You can not give a value in validation rule as the return type should be boolean. You can just make sure it is entered properly as per the condition given like in the formula.



Workflow rule:
And, you can use workflow rule where the rule checks if(a.Site!='') and if so, do a field update which gives the value 'www.anna.com' to the Site field.

Workflow rule:

User-added image

Field Update:
User-added image

Do not forget to activate the workflow once everything is set up.

 

All Answers

Jithesh VasudevanJithesh Vasudevan
Hi Sunil,

If you just need to change the site to the above value, you can use the below code,

trigger accountSite on Account (before insert) {
    for(Account a:Trigger.new){
      if(a.Site=='www.a.com'){
      
       a.Site='www.anna.com';
       
      }
    }

}


If there is any calculation on how to get 'www.anna.com' out of 'www.a.com', then we need to change the above code as it just changes the value without any further calculation. Let me know.
Sunil Kumar 545Sunil Kumar 545
any other webiste if i give means it should come as(www.anna.com)...not only for this website(www.a.com)...any website give in field it must be (www.anna.com)..before insert  using triggers
Sunil Kumar 545Sunil Kumar 545
same requriment how to use in validation rule ?
Jithesh VasudevanJithesh Vasudevan
Hi Sunil,

Ok. Then, you can give the condition like this,
 if(a.Site!='') in the trigger.



Validation rule:
If you want to use validation rule, you can use the below formula for Site field,

IF( Site <> 'www.anna.com',true,false)

This means if the site value is not 'www.anna.com' then it should throw an error. It will only save one value and that is 'www.anna.com'.

You can give an error message and give instructions to the user to choose the site as 'www.anna.com'.

You can not give a value in validation rule as the return type should be boolean. You can just make sure it is entered properly as per the condition given like in the formula.



Workflow rule:
And, you can use workflow rule where the rule checks if(a.Site!='') and if so, do a field update which gives the value 'www.anna.com' to the Site field.

Workflow rule:

User-added image

Field Update:
User-added image

Do not forget to activate the workflow once everything is set up.

 
This was selected as the best answer
Sunil Kumar 545Sunil Kumar 545
same requirement above question ..have do in (adderror). in any website if i give means it should come as(www.anna.com)...not only for this website(www.a.com)...any website give in field it must be (www.anna.com)..it should throw an error.
before insert  using triggers