• Tomeka Wray
  • NEWBIE
  • 40 Points
  • Member since 2015
  • Project Manager
  • Department of Commerce

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 11
    Replies
I am trying to grab the picklist values from the State field on my Lead object. The State field is part of the Address date type. The following code returns nothing:
List<Schema.PicklistEntry>  fieldResult = Lead.State.getDescribe().getPicklistValues();
        system.debug('States = ' + fieldResult);
        
        Map<string,string> options = new Map<string,string>();
		for( Schema.PicklistEntry f : fieldResult )
   			{
      			options.put(f.getLabel(),f.getLabel());
                system.debug('State =' + f.getLabel());
   				}

 
I have a Apex class that automatically creates a lead when certain conditions apply to case from another Org. However, the state field is a picklist and somestimes the field values from the sending org are not always in the receiving orgs picklist. How can I validate that the State received is actually in the picklist. 

My initial thought was to create a string array with all of the valid values and compare the state against that, but if the picklist changes, then my code will not be accurate. Any suggestions would be much appreciated. 
I have created an after insert trigger for Case object that creates a corresponding lead when it is accepted from a Salesforce to Salesforce Connection. However, when I try to retrieve the field values after the insert they are null except for the ID. Can you please take a look at my code to see what I am doing wrong.

trigger createCaseLead on Case (after insert) {
    List<Case> updatedCases = Trigger.new;
    system.debug('Number of cases =' + updatedCases.size());
    List<Lead> caseLead = new List<Lead>();
     //Loops Through all of the new Cases and Creates
    //a corresponding lead
    for (Case c : updatedCases){
        system.debug('ID = ' + c.ID);
        system.debug('LastName = ' + c.Contact_Name_Copy__c); //This is returning null
        system.debug('Company = '+ c.Org_Name__c); //This is returning null
        caseLead.add(new Lead(Company = c.Org_Name__c,
                              Street = c.Org_Street__c,
                              City = c.Org_City__c,
                              State = c.Org_State__c,
                              Country = c.Org_Country__c,
                              email = c.Copy_Contact_Email__c,
                              LastName = c.Contact_Name_Copy__c,
                              LeadSource = 'Department of Commerce Customers',
                              Case_ID__c = c.Id,
                             How_did_you_find_this_Company1__c = 'DOC - ' + c.Fee_Based_Service__c
                             ));

    }
    insert caseLead;
 
}
I have seen post for this error but no solution, so I am posting again in hopes of getting an answer. I am trying to send a record to a Salesforce to Salesforce connection if it meets certain parameters. However, received the error posted in the subject line. Below is the code that I am trying to execute:

trigger SimpleCaseTrigger on Case (after update) {
    // Define connection id 
    Id networkId = ConnectionHelper.getConnectionId('Connection Name'); 
    List <Case> sendToConn = New List<Case>();
    List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>();
    for (Case c : Trigger.New){
        //Test to that the case has been successfully closed and has not been sent to Connection Before
        if (c.ConnectionReceivedId == null && c.ConnectionSentID == null && c.Status == 'Successfully Closed'){
            sendToConn.add(c);
            System.debug('Case #'+ c.CaseNumber + ' added.');
        }
    }
    
    //Create Connection to send to Connection
    for (Case newCases : sendToConn){
        PartnerNetworkRecordConnection newConnection =
                    new PartnerNetworkRecordConnection(
                        ConnectionId = networkId,
                        LocalRecordId = newCases.Id,
                        SendClosedTasks = false,
                        SendOpenTasks = false,
                        SendEmails = false,
                        ParentRecordId = newCases.AccountId);
        prncList.add(newConnection);
    }
    database.insert(prncList);
    
}
 
Good Morning, 

I am trying to write a trigger for the case object that will send the record to a connection if it meets certain criteria. However, I don't want to envoke the code if the record was previously sent. Is there a way to see if the record was previously sent to a connection. I don't see any standard fields in the object field list that correlate to S2S.Thanks.
I am trying to grab the picklist values from the State field on my Lead object. The State field is part of the Address date type. The following code returns nothing:
List<Schema.PicklistEntry>  fieldResult = Lead.State.getDescribe().getPicklistValues();
        system.debug('States = ' + fieldResult);
        
        Map<string,string> options = new Map<string,string>();
		for( Schema.PicklistEntry f : fieldResult )
   			{
      			options.put(f.getLabel(),f.getLabel());
                system.debug('State =' + f.getLabel());
   				}

 
I have a Apex class that automatically creates a lead when certain conditions apply to case from another Org. However, the state field is a picklist and somestimes the field values from the sending org are not always in the receiving orgs picklist. How can I validate that the State received is actually in the picklist. 

My initial thought was to create a string array with all of the valid values and compare the state against that, but if the picklist changes, then my code will not be accurate. Any suggestions would be much appreciated. 
I have created an after insert trigger for Case object that creates a corresponding lead when it is accepted from a Salesforce to Salesforce Connection. However, when I try to retrieve the field values after the insert they are null except for the ID. Can you please take a look at my code to see what I am doing wrong.

trigger createCaseLead on Case (after insert) {
    List<Case> updatedCases = Trigger.new;
    system.debug('Number of cases =' + updatedCases.size());
    List<Lead> caseLead = new List<Lead>();
     //Loops Through all of the new Cases and Creates
    //a corresponding lead
    for (Case c : updatedCases){
        system.debug('ID = ' + c.ID);
        system.debug('LastName = ' + c.Contact_Name_Copy__c); //This is returning null
        system.debug('Company = '+ c.Org_Name__c); //This is returning null
        caseLead.add(new Lead(Company = c.Org_Name__c,
                              Street = c.Org_Street__c,
                              City = c.Org_City__c,
                              State = c.Org_State__c,
                              Country = c.Org_Country__c,
                              email = c.Copy_Contact_Email__c,
                              LastName = c.Contact_Name_Copy__c,
                              LeadSource = 'Department of Commerce Customers',
                              Case_ID__c = c.Id,
                             How_did_you_find_this_Company1__c = 'DOC - ' + c.Fee_Based_Service__c
                             ));

    }
    insert caseLead;
 
}
I have seen post for this error but no solution, so I am posting again in hopes of getting an answer. I am trying to send a record to a Salesforce to Salesforce connection if it meets certain parameters. However, received the error posted in the subject line. Below is the code that I am trying to execute:

trigger SimpleCaseTrigger on Case (after update) {
    // Define connection id 
    Id networkId = ConnectionHelper.getConnectionId('Connection Name'); 
    List <Case> sendToConn = New List<Case>();
    List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>();
    for (Case c : Trigger.New){
        //Test to that the case has been successfully closed and has not been sent to Connection Before
        if (c.ConnectionReceivedId == null && c.ConnectionSentID == null && c.Status == 'Successfully Closed'){
            sendToConn.add(c);
            System.debug('Case #'+ c.CaseNumber + ' added.');
        }
    }
    
    //Create Connection to send to Connection
    for (Case newCases : sendToConn){
        PartnerNetworkRecordConnection newConnection =
                    new PartnerNetworkRecordConnection(
                        ConnectionId = networkId,
                        LocalRecordId = newCases.Id,
                        SendClosedTasks = false,
                        SendOpenTasks = false,
                        SendEmails = false,
                        ParentRecordId = newCases.AccountId);
        prncList.add(newConnection);
    }
    database.insert(prncList);
    
}
 
Error: 
Apex trigger partnersync caused an unexpected exception, contact your administrator: partnersync: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_PARTNER_NETWORK_STATUS, invalid status for partner network operation: []: Trigger.partnersync: line 19, column 1

Code:
trigger partnersync on Partner__c (after insert,after Update) {
    Id networkId = ConnectionHelper.getConnectionId('Academy of Financial Trading 2nd Org');
    List<PartnerNetworkRecordConnection> partnerConnections =  new  List<PartnerNetworkRecordConnection>();
    
    for (Partner__c pl : trigger.new) {
        
        PartnerNetworkRecordConnection newConnection = new PartnerNetworkRecordConnection(
            
            ConnectionId = networkId,
            LocalRecordId = pl.Id,
            SendClosedTasks = false,
            SendOpenTasks = false,
            SendEmails = false,
            ParentRecordId = pl.Id);
        partnerConnections.add(newConnection);
    }
    if (partnerConnections.size() > 0 ) {
        database.insert(partnerConnections);
        
    }
    
}

I am trying to implement a very simple auto sharing Salesforce to Salesforce trigger and it is throwing an error that makes no sense. I am developing this in the Sandbox and I have created a connection to another sandbox.

 

Invalid_Partner_Network_Status

 

I have been debugging things so that I know the ConnectionId, LocalRecordId, and ParentRecordId's are all accurate. The problem is that when it goes to insert the connection it throws the error above. 

 

Now according to the PartnerNetworkRecordConnection page below, this error is thrown when either the connecting org is not subscribing to the object that is being shared OR when you try to share a record that is already being shared. Neither of these can be the case as I am running the trigger as an 'AFTER INSERT' trigger so the opportunity is brand new. And I can manually share and accept the opportunity with the other sandbox org.

 

Why else could this error be thrown??? 

 

Please help!

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_partnernetworkrecordconnection.htm