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
NatureGodNatureGod 

Simulate an edit/save on parent object

Greetings,

 

I am to Simulate an edit/save on parent object, which is a custom object, Cunsumer__c from its child, a Standard, Solutions.

 

The code I wrote is:

 

trigger AutoUpdateConsumer on Solution (after insert,after update) {
List<Solution> S = [Select Solution.Consumer__c From Solution];

// String Sol = '0000000042';
id Sol = S[0].Consumer__c;

List<Consumer__c> Con = [Select Consumer__c.Name From Consumer__c where Consumer__c.Name =: Sol ];

Database.update(Con);

}

 

This works fine for Sol =  '0000000042' (in comments) but not for a dynamic, the id which is valid when we edit the specific Solution record and everyone which has the same parent Cunsumer.

 

Any Help really appreciated.

 

Stefanos

TheDoctorTheDoctor

Have you tried using Solution.Consumer__r.Id instead of Solution.Consumer__c?

NatureGodNatureGod

I tried but it does not work...

 

trigger AutoUpdateConsumer on Solution (after insert,after update) {
List<Solution> S = [Select Solution.Consumer__r.id From Solution];

// String Sol = '0000000042';
id Sol = S[0].Consumer__r.id;

List<Consumer__c> Con = [Select Consumer__c.Name From Consumer__c where Consumer__c.Name =: Sol ];

Database.update(Con);

}

 

Any suggestions?

AshlekhAshlekh

Hi ,

 

 

The Consumer__c.name is text type field if you are storing id in the text field than you can tyr this.

 

this will give record.

 

String  Sol = S[0].Consumer__c;

List<Consumer__c> Con = [Select Consumer__c.Name From Consumer__c where Name =: Sol ];

 

 

But if you use this wil not retrun any value.

Id Sol = S[0].Consumer__c;

List<Consumer__c> Con = [Select Consumer__c.Name From Consumer__c where Name =: Sol ];

  

Thanks 

Ashlekh

 

If this post helps you than please mark it as a solution and don't forget to give me kudo's .Thanks

 

NatureGodNatureGod

Hi D-Horse,

 

I tried but did not work,

 

Actually what is needed is an iconic update/save to the parent custom object Consumer__c, whenever an edit happens in one of its children the standard Solution.

 

If htere is a simpler way I would really appreciate.

 

Many thanks,

Stefanos

AshlekhAshlekh

Hi,

 

Please tell me your object name and relationship between them and then what doo you want todo, and what type of error you are facing.

I think i am not getting your point so please provide this info then may be i will help you.

NatureGodNatureGod

Hi,

 

Relationship:

 

1 Consumer__c to many Solution(s)

Custom to Standard object.

 

I want to update a points field in the Consumer whenever we have an addition of points in the standrad Solutions.

This now is only achievable if we edit/save the record in the Consumer__c.

I want to simulate an edit /save when a record in Solution related to the consumer__C is edited/saved.

 

Many thanks,

Stefanos