Salesforce: Update Managed Object's Auto number Field... - salesforce

I would like to know if we can update auto number field. When I tried updating using Dev Console system said : 'Field is not Writable'
In our support product(Managed Package), I need to update/ start auto number field from specific number say 100.
I am thinking of creating a text field and imitate is as that Auto Number field. But I don't know how much will it hamper existing functionality of the package.
Any idea.
Thanks in advance.

You cant set new values to auto number fields in Salesforce. But you can use for this custom field with number type, which will be automatically filled in using the trigger. In the trigger you can implement any logic to check the uniqueness of fields and check all its conditions. If you want input values of this field manually, you can use validation rules for checking the uniqueness.

Related

Updating to Salesforce user object using informatica

I have three fields badge number, termination date and status to update to Salesforce based on badge number.im using update strategy in mapping and on session level -upsert with external lookup field as badge_number_c and treat source rows as data driven(session properties). However we get only 50 records updated and 20000 records rejected as badge numbers not present in target and those 20 k records trying to insert and hence rejected(since we did not map all fields to form record in Salesforce as we only update).. for this error log it consuming lot of time and wf run time is high.
I tried to remove upsert and external lookup field but it throws error as I'd field missing..
it looks like you are trying to update salesforce target using infa target definition and mixing two things.
If you are using only update strategy + treat source rows as data driven(session properties), then please ensure you handle update condition in update strategy.
For example,
First calculate INSERT_UPDATE_FLAG using some lookup on target by joining on primary key columns.
And then use it like below logic in update strategy.
IIF ( INSERT_UPDATE_FLAG = 'UPD',DD_UPDATE, DD_INSERT) -- if you want UPSERT logic.
or
IIF ( INSERT_UPDATE_FLAG = 'UPD',DD_UPDATE, IIF(1=2,DD_INSERT)) -- if you want only UPDATE logic.
Also pls note, you need to mention primary key columns in infa target definition otherwise update wont work.
Now as per your screenshot, if you want to use SFDC specific logic, probably, you need to be careful and follow below link to do this. Its a multi step process to create external id first and then use it to do lookup and update.
https://knowledge.informatica.com/s/article/124909?language=en_US

how to put a formula ontop of a rollup field summary?

Setup
I have a Master-Detail relationship, and on the master, I sum up a field from the Detail object.
Question:
I need to allow the user to check a box on the master object which will add the sum by 1 or decrement by 1. How do I do this?
Here's what I've tried:
In an after update trigger on the master increment/decrement within the trigger. Of course I get an error:
expected exception, contact your administrator: NonCashCompAfterUpdate: execution of
AfterUpdate caused by:
Created a new field, and used the existing field as a helper. Basically, I've hidden the old RFS while still using it. This works, but I wanted to see if there was a better way.
Before I went any further I wanted to check in for ideas.
Thanks!
There is no way to directly alter values on a roll-up summary field in salesforce, except by altering the underlying detail records. The second proposal, as I understand it, would involve three fields, the roll-up summary, the checkbox, and the displayed summary (which would be a formula field). The displayed summary field would look something like this:
Rollup_Summary_Field__c + IF(Checkbox_Field__c, 1, -1)
The read-only nature of a roll-up summary field is preserved in Apex as well, so you would not be able to alter it through a trigger. Presumably, that is the nature of the error that you got, though the excerpt that you have attached omits the actual error.

can we do validation or save entered field as full caps while saving the record

I have a situation where i am querying using value entered in the record. if the value entered in the field is small letters and the ones in the objects are caps then the result is not correct as they are case sensitive.
Is there a way i can have the values entered all in caps? I know i can write a trigger to do it. Is there something in admin which would force this
Are you querying using Apex? If so, do String.toUpperCase() on the search terms.
If you are using a Salesforce page you can either create a formula for the field being saved from the SETUP menu on the object you are saving to.
Or you could create a workflow that would change the case to upper-case on new and update.
If you are using a Visualforce page, you can create a Before trigger and set the test to string.touppercase like Jeremy Ross has suggested.

Prevent duplicate records in custom object

I have a custom object. There are combination of fields like month_c,Project_c,contact_c and role_c which determine the record as unique.
I can write a trigger on before insert to check if there are any records with the same combination already existing. The question i wanted to ask was
how can i make the insertion stop. once i find there is already an record then it should just not insert the record. it doesnt need to throw / show an error.
Thanks
Prady
Although others have answered this with better solutions (generally non-code solutions are more flexible for the end users of the system), the answer to stop a particular record from being inserted is to add an error to a field on that record.
For instance, if I was inserting accounts I might have something like this:
for(Account sAcct : trigger.new)
{
if(sAcct.Name == 'DeniedAccount')
{
sAcct.Name.addError('This is a denied account.');
}
}
Another alternative is to create a class extending Exception, and then throw a new instance of that exception class, this will prevent all of the records passed to the trigger from being processed as opposed to specific records.
A few days ago I found an incredibly useful and simple solution (in a ForceTree.com article) that prevented me from having to write a trigger. It allows you to combine fields to check for uniqueness using a workflow rule and a custom field.
Here's a walk-through:
http://www.forcetree.com/2010/07/unique-field-combination-in-salesforce.html
I have a similar situation in Salesforce. It is handled by creating a field that contains a value composed of all the values needed to guarantee uniqueness (in your case, month_c,Project_c,contact_c and role_c ). You then select the "Unique" checkbox for that field. Duplicates will now end up in the trash.
In my case, this new field is filled in (and pushed into Salesforce) by an external program. In your case, you'll need to fill in the value in your trigger. I think this is more efficient than doing SOQL queries in a trigger, but I have not done any checking to confirm this.

Non editable field in database

Sorry for this lame question, but I really am a database newbie:
I want to store the date when I create a certain field on the database. Is there any attribute I can add to that date field so that it cannot be modified? I just want the date field to have the date when a field is created on never want to edit it.
I am using PostgreSQL.
Thanks.
There is no way to actually do this; however, if you want to make this occur you would perform a trigger on update for that specific table.field and throw a DBMS error. There might be a more elegant way to do this; but this is all I can think of to protect a specific value once it has been written.
I think PostgreSQL supports column level permissions. Check this : PostgreSQL 8.4 Feature List

Resources