+ Start a Discussion
DeptonDepton 

Previous picklist value on record

Hi,

 

I am trying to get the previous stage value showing up in a custom field without success.

 

Do you now how can I have a "previous stage" field in the record without having to use the history tracking!

 

It is for reporting and I can not track on opportunities with products and history tracking!!!

 

Any ideas.....??

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
craigmhcraigmh

Or a trigger.

 

trigger ObjectChanged on YourObject (before update) {
	for(integer idx = 0; idx < trigger.new.size(); idx++) {
		if(trigger.old[idx].StatusField != trigger.new[idx].StatusField) {
			trigger.new[idx].PreviousStatusField = trigger.old[idx].StatusField;
		}
	}
}

 

All Answers

kiranmutturukiranmutturu

do u want that previous stage value in a custom field on the same object itself?

DeptonDepton

Yes, Exactly!! :)

kiranmutturukiranmutturu

then create a custom field on the object and create a workflow on the same object and put the formula condition as ischanged(stagename) and rule critieria is when ever record is created or edited ..the create a workflow action as field update.....map that formula to the custom field in the object.. and the formula in the field update should be 

 

text(priorvalue(stagename)).....save and activate the same.....try this u will get the previous stage value in the custom field

craigmhcraigmh

Or a trigger.

 

trigger ObjectChanged on YourObject (before update) {
	for(integer idx = 0; idx < trigger.new.size(); idx++) {
		if(trigger.old[idx].StatusField != trigger.new[idx].StatusField) {
			trigger.new[idx].PreviousStatusField = trigger.old[idx].StatusField;
		}
	}
}

 

This was selected as the best answer
DeptonDepton

Thank you!!!!!!!!!!!! You are the man!!

 

:))

kiranmutturukiranmutturu

ya u can acheive this through code also..but my idea is to work with clicks not with code.......for this trigger again u need a test class to deploy but maintaining code is a challenge ...