You need to sign in to do that
Don't have an account?
Auto Update Name after saving
I have three fields on the object "Building"
1)Building Name Api Name "Name"
2)Location Api Name "Location__c" It is a lookup field to the obj "Location"
3)Date Api Name "Date__c"
When a user enters the building name ,location ,date and saves the record the Building Name should be autoupdated to
Building Name.Location.Date
date should be of the format "yyyy-mm-dd"
Can anybody shred light on to this and help me
Hi Steve,
Below is sample code for you, check if it helps:
All Answers
Something like this:
You may need to play with the date format piece, though.
EDIT:
It's trigger.isInsert, not trigger.isInser(). It's a property, not a method.
I am getting the location Id .How do i get the location Name
From which part of the code?
When i am saving the record the formula is coming
As Buildingname.595959jgkgffjf.2/12/2012
I need the name .Iamgetting the id
Oh, got it. Forgot that it was a lookup field. So you'd need to use the relationship name/name field, which will be similar to this:
When i give this way
the middle part i.e the location name is coming as null
Oh yeah, you'll have to change the if statements as well:
try
Its not working
How about:
**For insert you will either have to make up the Name or do it in an after insert
If this does not work, be more specific as to what you need please
When I am trying to update the location after insert i am getting eror as
Review all error messages below to correct your data.
Apex trigger updateName caused an unexpected exception, contact your administrator: updateName: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.updateName: line 8, column 1
Hi Steve,
Below is sample code for you, check if it helps:
Please use this code it may help you
trigger UpdateTriggerObject on objname (after insert)
{
set<id> nameId = new set<id>();
list<objname > trgList = new list<objname >();
for(objname t: trigger.new)
{
nameId.add(t.id);
}
trgList = [Select fieldname1, fieldname2, fieldname3 from objname where id = :nameId ];
for(integer i = 0; i < trgList.size(); i++)
{
trgList[i].fieldname1= trgList[i].fieldname2+'.'+trgList[i].fieldname3+'.'+date.today();
}
insert trgList;
}
took the logic from i t and had tweak somethings and also format of date doesnt work.Had used different approach.Thanks a lot