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
miguelguerreiro@live.commiguelguerreiro@live.com 

Trigger one object and query another object

Hello,

 

I have a object Industry (with lookup on Accounts and some text fields). Then another object Results (also linked with Accounts) that is manually imported.

 

Can I create a trigger that every time I create a Results record would query the Industry object and would return some of it's text fields to be copied to the Results record?

Best Answer chosen by Admin (Salesforce Developers) 
anil 007anil 007

HIII

 

 

just try it will work

All Answers

anil 007anil 007

Haii

 

i did it for account and contact objects instead of custom objects

 

try this one....

 

 

trigger account1 on Account (after insert,after update) {
List<Contact> con=new List<Contact>();


List<Account> acc=[select id,name from account where id in : trigger.new ];


if(Trigger.isInsert)
{

for(account c:acc)
{

con.add(new Contact(lastname=c.name));

insert con;
}    
 
}



if(Trigger.isUpdate)
{
List<Account> acct=[select id,name from account where id in : trigger.old];
for(account c:acct)
{

con.add(new Contact(lastname=c.name));
insert con;
}     
}

}

miguelguerreiro@live.commiguelguerreiro@live.com

Do you think it will work (with some modifications) for this example:

 

When a Result entry (ResultField1 = "A", ResultField2 = "B") is created, the trigger would check in Industry objects if there any record with IndustryField1 = "A", IndustryField2 = "B" and would copy IndustryField3 value to ResultField3.

anil 007anil 007

HIII

 

 

just try it will work

This was selected as the best answer