Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Help with Triggers
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Help with Triggers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-27-2012 07:00 AM
I have 4 objects and their relatinoship is like this:
Case-> Account
Opportunity->Account
Case->Caseopp
Caseopp-> Opportunity
I have created a new field on Opportunity as " Test".
what am trying to do is I need to copy the status of Case on this field "Test" only on those Opportunity which exists on Caseopp by trigger.
Can anyone help me with this?
Solved! Go to Solution.
Re: Help with Triggers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 12:30 AM
Try this code:
trigger UpdateStatus on Case(before insert, beforeupdate)
{
for ( Case c : Trigger.new )
{
caseopp__c co= [select opportunity__c from Caseopp__c where id = :c.Caseopp__c];
opportunity o= [select test__c from opportunity where id = :co.opportunity__c];
o.test__c=c.status;
update o;
}
}
Madhan Raja M
Re: Help with Triggers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 06:32 AM
Hi,
This trigger gives me an error:
Error: Compile Error: Invalid field CaseOpp__c for SObject Case at line 5 column 97
FYI: CaseOpp is an junction object between Case and Opp
Re: Help with Triggers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 06:35 AM
And also I need to populate the Case status on Opportunity [Test field], so why are we creating trigger on Case?
Re: Help with Triggers
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 07:16 AM - edited 09-28-2012 07:23 AM
Caseopp is a junction object and the API Name for Caseopp is CaseOpp__c.
Replace CaseOpp__c with your junction Object API Name.
If this doesn't solve your problem, I have a question for you.
Have you created Two lookups one for Case and the other for Opportunity in CaseOpp junction object?
Madhan Raja M
Re: Help with Triggers
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 07:22 AM - edited 09-28-2012 07:23 AM
Once you create/update the status in case record then the trigger will update the Test fields in opportunity with Case status.
Madhan Raja M
Re: Help with Triggers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 07:45 AM
Yes the API name for Caseopp [Juntion object] is CaseOpp__c and I laready replaced it and I got the same error.
Yes I have created 2 lookups one for case and other for opportunity in CaseOpp junction object.
Re: Help with Triggers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 11:32 AM
Try this out:
trigger UpdateStatus on Case(before insert, beforeupdate)
{
for ( Case c : Trigger.new )
{
Caseopp__c co= [select case__c, opportunity__c from Caseopp__c where case__c= :c.id limit 1];
opportunity o= [select test__c from opportunity where id = :co.opportunity__c];
o.test__c=c.status;
update o;
}
}
Re: Help with Triggers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 12:29 PM
I am still getting this error:
Error: Compile Error: Invalid field CaseOppAssociation__c for SObject Case at line 5 column 97
Trigger used is:
trigger UpdateStatus on Case(before insert, before update)
{
for ( Case c : Trigger.new )
{
CaseOppAssociation__c co= [select opportunity__c from CaseOppAssociation__c where id = :c.CaseOppAssociation__c];
opportunity o= [select Trigger__c from opportunity where id = :co.opportunity__c];
o.Trigger__c=c.status;
update o;
}
}
Re: Help with Triggers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-28-2012 09:50 PM
Paste this code and try, it should work:
trigger UpdateStatus on Case(before insert, before update)
{
for ( Case c : Trigger.new )
{
CaseOppAssociation__c co= [select case__c, opportunity__c from CaseOppAssociation__c where case__c= :c.id limit 1];
opportunity o= [select test__c from opportunity where id = :co.opportunity__c];
o.test__c=c.status;
update o;
}
}

