• Dima.Smirnov
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
HI , I have a trigger on Opportunity for Sharing Records using Salesforce to Salesforce Connection.

When a opportunity is created Trigger fires and shares the Opportunity and Account to the target Org. Everything Works , i have  some triggers in Target Org to re-establish  Account and Opportunity As Salesforce to salesforce does not support lookup relationship.

Problem is My opportunities are cretaed by Lead Conversion and at that time my trigger fires and Opportunity Gets Created in Target Org and Related Account is also cretaed but the LookUp relation is not established. I believe the reson behind it is as Opportunity and Account are cretaed at the same time during lead Conversion trigger is not able to find the account to relate to Opportunity . how to handl this

Trigger autoforwardOpportunity on Opportunity(after insert) {
    String UserName = UserInfo.getName();
    String orgName = UserInfo.getOrganizationName();
    List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>(
        [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']
    );
    System.debug('Size of connection map: '+connMap.size());
    List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>();
   
    for(Opportunity opp: trigger.new){
   
        String acId = Opp.Id;
        System.debug('Value of OpportunityId: '+acId);
        for(PartnerNetworkConnection network : connMap) {
            String cid = network.Id;
            String status = network.ConnectionStatus;
            String connName = network.ConnectionName;
            String AccountName = Opp.Accountid;
            String AssignedBusinessUnit = Opp.Assigned_Business_Unit__c;
            System.debug('Connectin Details.......Cid:::'+cid+'Status:::'+Status+'ConnName:::'+connName+','+AssignedBusinessUnit);
            if(AssignedBusinessUnit!=Null && (AssignedBusinessUnit.equalsIgnoreCase('IT') || AssignedBusinessUnit.equalsIgnoreCase('Proservia'))) {    
                // Send account to IT instance
                PartnerNetworkRecordConnection newAccount = new PartnerNetworkRecordConnection();
                newAccount.ConnectionId = cid;
                newAccount.LocalRecordId = Opp.AccountId;
                newAccount.SendClosedTasks = true;
                newAccount.SendOpenTasks = true;
                newAccount.SendEmails = true;
                newAccount.RelatedRecords = 'Contact';
                System.debug('Inserting New Record'+newAccount);
                insert newAccount;
               
                // Send opportunity to IT instance
                PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
                newrecord.ConnectionId = cid;
                newrecord.LocalRecordId = acId;
                newrecord.SendClosedTasks = true;
                newrecord.SendOpenTasks = true;
                newrecord.SendEmails = true;
                //newrecord.RelatedRecords = 'Contact';
               // newrecord.ParentRecordId = Opp.AccountId;                             If i use this trigger throws an error saying invalid status as there is no account yet.
                System.debug('Inserting New Record'+newrecord);
                insert newrecord;
            }
        }
    }
}

  • February 26, 2014
  • Like
  • 0

Hi..All

can we retrive  Job ID from CronTrigger?,

if yes then please tell me how we can retrieve it...

 

Thanks,

Akshay