• Isak Stensmar 8
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hello,

I have a problem with one of my functions in one of me classes.
The scenario is as follows:
I override the Save functionality by adding some other code to the function after the record has been inserted.
The other code include a query to get the latest Opportunity, which is created by a trigger when a new record is inserted.
I then have a PageReference that sets the current page to a process template, that is implemented by another app from appexchange, which need an OpportunityID.
public PageReference save()
    {
        List<Opportunity> opp;
        insert myMD_Object;
        try{
        	opp = [SELECT Id FROM Opportunity ORDER BY CreatedDate DESC];
        }
        catch(Exception e) 
       {}
        currentPage = new PageReference('/apex/scrive__scrivedocumentfromtemplate?Id=a0E4E000000DAp3UAG&sourceRecordId=' + opp[0].id);
        currentPage.setRedirect(true);
        return currentPage;
    }
The problem is that when I create and insert a new record, which would trigger insertion of an oppertunity aswell, the query after the insertion doesn´t find it. 

I´ve read a little about how the function is one big transaction and that could be one reason to why the query doesn´t find it, since the transaction isn´t complete. So I thought about how I should solve this, if I could split up the transaction in to two parts.
This article http://salesforce.stackexchange.com/questions/77490/can-i-have-multiple-transactions-within-1-schedulable-class had an interesting way of solving the problem, but I couldn´t make it work on my own code. I´ve read about BatchableContext and SchedulableContext but it didn´t make me much wiser.
That article doesn´t talk about how you can call on these functions from a visualforce page either, which I need to do.
So I´m wondering how I should solve this. I liked the way that the article above was using but can´t seem to figure it out. I also need to figure out if/how I can call on a batch or schedule from a visualforce page.

Any thoughts?

Regards,
Isak
Hi,

I have a lookup relationship on a custom object which relate to itself, so it is possible that 1stObj links to 2ndObj, 2ndObj links to 3rdObj and so on.
I´m trying to access the value from the lookup field but I don´t know how to proceed and I´m not really sure how relationships works (even though I´ve read guides and other peoples solutions).

My code basically look like this where I try to access the value from the lookup field.
<apex:page standardController="MonthlyDonor__c">
    <apex:outputLink value="{!MonthlyDonor__c.Link_Objects__r.Id" title="Linked Object"> Linked Object </apex:outputLink>
MonthlyDonor is my custom Object.
Link_Objects is my Lookup field which relate to MonthlyDonor.
Link_Objects contains a MonthlyDonor ID from another MonthlyDonor.
I´ve tried using only the monhtlydonorid or __c but that does not work.
I´ve also tried to create an extension to the standardController but without any luck.
Any solutions or adivce would be greatly appriciated.

/Isak
 
Hi,

I want to update an existing record Lookup field when I insert a new record.
My last post ( https://developer.salesforce.com/forums/?id=906F0000000DCnZIAW ) was also about linking records but in that case it was only the record that was inserted that was linked to an existing record.

What I want to accomplish this time is to update the lookup field on an existing record when a new record is inserted.
The problem I´ve faced so far is: 
-No ID before insert, so I can´t update lookup field in a (before insert) trigger (if I want to use the new record's ID that is).
-(After insert) trigger has ID, but you can´t update records in (after insert) triggers.

 Any suggestions/solutions?

Regards,
Isak
 
Hi,

I´m trying to create a trigger that link two objects of the same object type.
This is what I´ve come up with so far...
Trigger CheckIfExists on MonthlyDonor__c (before insert) 
{

    MonthlyDonor__c md_Object;
    
    List<MonthlyDonor__c> md1=[Select id from MonthlyDonor__c where MonthlyDonor__c.SSN__c=:trigger.new[0].SSN__c];
    if(md1.size()>0)
    {
        md_Object = md1[0];
        
        md_Object.Link_Objects__c = trigger.new[0].id;
    }
}
The trigger should check if an object (monthlydonor) allready exists in the database by comparing the SSN number from the object im trying to insert.

If md1.size()>0 it indicates that an objects exists and I should now link these objects together.

This is where I´m stuck. I´ve looked at relationships between objects but haven´t figured it out yet and could use some help.
Link_Objects__c is of the type Lookup and I thought the easiest way to link two objects was with the id, but I cant see any value in the lookup field for my object when I´m testing it.

Any help would be appreciated.

Regards,
Isak
 
Hi,

I´m trying to create a trigger that link two objects of the same object type.
This is what I´ve come up with so far...
Trigger CheckIfExists on MonthlyDonor__c (before insert) 
{

    MonthlyDonor__c md_Object;
    
    List<MonthlyDonor__c> md1=[Select id from MonthlyDonor__c where MonthlyDonor__c.SSN__c=:trigger.new[0].SSN__c];
    if(md1.size()>0)
    {
        md_Object = md1[0];
        
        md_Object.Link_Objects__c = trigger.new[0].id;
    }
}
The trigger should check if an object (monthlydonor) allready exists in the database by comparing the SSN number from the object im trying to insert.

If md1.size()>0 it indicates that an objects exists and I should now link these objects together.

This is where I´m stuck. I´ve looked at relationships between objects but haven´t figured it out yet and could use some help.
Link_Objects__c is of the type Lookup and I thought the easiest way to link two objects was with the id, but I cant see any value in the lookup field for my object when I´m testing it.

Any help would be appreciated.

Regards,
Isak