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
venu kingvenu king 

Working With Triggers

I had situation to create a trigger when i update a field then all the records with that field should be changed to same value can any one guide me (any sample code )..

gbu.varungbu.varun

You should start from baisc. Here is the link to start your first trigger.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_trigger.htm

Dave Miller.ax1920Dave Miller.ax1920
Do you mean "all records that have the same old value in that field" ?
venu kingvenu king

Hi

Yes,all the records that have the same value like (true, false ) 

 

For Example if i had check box field when i checked it all the records with that field should be checked and vice- versa.....

 

How can i achieve this  Trigger or WorkFlow ???

 

Dave Miller.ax1920Dave Miller.ax1920

I haven't got time for valid syntax code but something like

in the trigger

 

 

for( things x1 : Trigger.new )

{

    list<things> changethese = [ SELECT Id, field1 FROM things WHERE field1!=:x1.field1 AND Id1= x1.Id ];

    for ( things x2 : changethese )

    {

        x2.field1 = x1.field1;

    }

    update changethese;

}

 

Or you could just create a single GlobalValues record and put the tick in there?.....

 

I'm intrigued why you have a value that has to be the same in every record?

You could almost just say


    list<things> changethese = [ SELECT Id, field1 FROM things WHERE Id1= x1.Id ];