Need Help Regarding Validation Rule - salesforce

I want to write validation rule on quote object, Whenever Order Type is 'Direct billing to customer' And transaction Type is 'Scheme' , 'VLC' then other 2 fields(Req_Cont__C, Retention__c)should be only read only while creation and updation
I have written this below validation but its not working
AND(ISPICKVAL( Order_Type__c, 'Direct Billing To Customer '),
ISPICKVAL(Transaction_Typee__c, 'scheme')||
ISPICKVAL(Transaction_Typee__c, 'VLC'),
AND(ISBLANK(Req_Cont__C), ISBLANK(Retention__c) ) )
Need solution
Thank You

Related

How can i insert a custom object into Slaesforce using Apex with requiredfields that are non-writeable?

A client has created a custom object call CustObj__c in Salesforce. They have required fields , one is Cust_Id which is of type Formula (Text)
I am trying to create a Custom Object item using the following
List<CustObj__c> CustList = new List<CustObj__c>();
CustObj__c Item_0 = new CustObj__c( Name__c='TEST1', Cust_Id='Cust: '& 123);
CustList.add(Item_0);
CustObj__c Item_1 = new CustObj__c( Name__c='TEST2', CustId__c='Cust: '& 456);
CustList.add(Item_1);
insert CustList;
But it gives the error that
Field is not writeable: CustObj__c.CustId__c
How can i insert if the field is non writeable but required ?
If it is a custom metadata object , do i need to do this ?
client hasnt provided any details
Formula fields are calculated at runtime when you view the record and are readonly, can't be marked as required. If your client has business need for it to be required they probably created a validation rule that checks the field value.
You'll have to inspect the field's formula and insert data that would satisfy it. (Some other fields populated, maybe some dates or right amounts). Maybe they assign customer id(?) in some special way, only if account reaches certain status, moves from prospect to paying customer.
You could ask them if they ever had to write unit tests that insert these records and steal get inspired by these code samples, see what prerequisites there are or fields that impact that formula.

how to update custome field with standard field value?

Using sales force i want to update a custom field value with the value of the account name using workflow ,i have created the custom field named (Name__c) and also the workflow but i don't know what is the data i should fill the workflow with to update this value to make the account name as a unique but i could not find the exact steps i should make to perform this action
and also i have used
ISNEW() || ISCHANGED(Name) || ISBLANK(Name__c)
but i got an error message said "Error: Function ISNEW may not be used in this type of formula"
sorry as i am new in sales force technology
Mark the custom field named (Name__c) as UNIQUE in custom field definition.
Set the Rule Criteria : Name(standard field) not equal to null.
Evaluation Criteria : Evaluate the rule when a record is created, and any time it’s edited to subsequently meet criteria
Add the field update workflow action to copy the Name to Name__c

Salesforce Junction Objects

To all salesforce experts i need some assistance. I have my contacts and a custom object named programs. I created a junction object using to master detail relationships with contacts and programs. I want to avoid relating the same contact to the same program. I tried triggers but I couldn't create the testing part to use it outside sandbox.
I went back to the basics and created a Unique text field. I tried to use default value but EVERYTHING i write in that crap is wrong -_-. I tried Contact__r.Email & "-" & Program__r.Name but to no avail.
I tried workflow rules with a field update but my field update NEVER runs.(Yes I did activate the workflow rule) and I didn't know what to write in my rule's code.
The workflow firing condition could be simply a formula that says true. Alternatively use "every time record is inserted". It also depends whether your master-details are set once and that's it or they will be "reparentable" (option introduced in Summer '12 I think). Maybe post a screenshot / text description of your firing condition? Also - is your unique field set to "case sensitive"?
As for the formula to populate the unique field - something like Contact__c + ' ' + Program__c (or whatever the API names of your fields are) should be OK. Don't use Contact__r.Email etc as these don't have to be unique...
You'll have to somehow fill in the uniqueness criteria for all existing records (maybe that's why you claimed it doesn't work?). If you can use Apex for data fixes - something like this should get you started.
List<Junction__c> junctions = [SELECT Contact__c, Program__c
FROM Junction__c
WHERE Unique_Text_Field__c = null
LIMIT 10000];
for(Junction__c j : junctions){
String key = String.valueOf(j.Contact__c).left(15) + ' ' + String.valueOf(j.Program__c).left(15);
j.Unique_Text_Field__c = key;
}
update junctions;
Keep rerunning it until it starts to show 0 rows processed. The Ids are cut down to 15 chars because in Apex you'd usually see full 18-char Id but workflows use 15-char versions.

Restrict users from putting the close date in the past, except for specific users

Trying to edit this validation rule which restricts users from updating opportunities (all open opps) if the close date is in the past, however, the user role mentioned doesn't seem to work. I'd like to allow just two users to be able to put a past close date if need be.
AND (
NOT ( CONTAINS( $UserRole.Name, "Manager")),
ISCHANGED( CloseDate ) ,
CloseDate < Today()
)
thanks,
I have had the same problem as well using CONTAINS with $UserRole.Name (or $UserRole.Anything really). Maybe CONTAINS only likes to work on columns that are in the database, I'm not sure. I would note though that it works fine if you use =, like $UserRole.Name="Line Manager". That's not ideal, but would it be a valid workaround for you?

Read only privileges to records in salesforce

I have to make a field read only after user has entered value in salesforce so that even that particular user cannot change the value once its entered. How could i achieve this. Thanks in advance.
To my knowledge, Salesforce does not have a "allow this field to be set only once" setting. Simplest way would probably be a validation rule that only throws an error when the field is changed and the field's previous value wasn't blank, something like:
AND(
ISCHANGED(SomeField__c),
NOT(ISBLANK(PRIORVALUE(SomeField__c)))
)
Or for a picklist:
AND(
ISCHANGED(SomeField__c),
NOT(ISPICKVAL(PRIORVALUE(SomeField__c), ''))
)

Resources