• Edward Encarnacion
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 7
    Replies
What is a better choice from the design and stability perspective for a below requirement.

When a Lead record exists in the system, based on the RecordType we should change the status of the Lead record type during the below timelines.

1. When Lead Created Date is more than 91 days old and stage='Prospecting' change status from Attempting to Interim Purge
2. When Lead Created Date is more than 98 days old and stage='Prospecting' change status from Interim Purge to Final Purge.

Volume of Leads created are 500-2000 leads per day.

I'm very new to this so any  help would be of great assistance!

I'm currently using the below trigger;
I'm trying to get the trigger to update the AccountOwnerID ONLY within "Contacts"  when the "Accounts" ownerID is changed.

Currently "Oppurtunities" is being changed as well, which defeats the purpose for us.

I'm not sure this is even possible, so any help would be greatly appreciated.
 

trigger Changeownertrigger on Account (after insert,after update) {
       
          Set<Id> accountIds = new Set<Id>();
          Map<Id, String> oldOwnerIds = new Map<Id, String>();
          Map<Id, String> newOwnerIds = new Map<Id, String>();
          Contact[] contactUpdates = new Contact[0];
          
          for (Account a : Trigger.new)
          {
             if (a.OwnerId != Trigger.oldMap.get(a.Id).OwnerId)
             {
                oldOwnerIds.put(a.Id, Trigger.oldMap.get(a.Id).OwnerId);
                newOwnerIds.put(a.Id, a.OwnerId);
                accountIds.add(a.Id);
             }

          }
            if (!accountIds.isEmpty()) {
             for (Account acc : [SELECT Id, (SELECT Id, OwnerId FROM Contacts) FROM Account WHERE Id in :accountIds])
                {
                String newOwnerId = newOwnerIds.get(act.Id);
                String oldOwnerId = oldOwnerIds.get(act.Id);
                for (Contact c : acc.Contacts)
                {
                   if (c.OwnerId == oldOwnerId)
                   {
                   Contact updatedContact = new Contact(Id = c.Id, OwnerId = newOwnerId);
                   contactUpdates.add(updatedContact);
                   }
                }
                 
                }
           }
                update contactUpdates;
    }

1.i am using standrad page to save record. In standard page i can not add or override a button  in edit page layout.

2.we can only add button in detail page layout

now on standard page save button click i want to show a VF page .how can we do that

is it possible to open a VF page through trigger

Thanks
Rahul Raturi

 
Hi

I am trying to get a trigger based on Contact to funciton but I am continually getting an error relating to too many SOQL Queries. The error states I am getting the error on Line 60.

Should I create a 2nd Contact Trigger file and have it only execute AFTER update?
LIST<Contact> thisCount = [SELECT Id FROM Contact WHERE OwnerId IN :ownerIds AND CCC_Adviser__c = TRUE];
 
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
//
//  Name:
//      CI_Trigger_Contact
//
//  Purpose:
//      This will process changes that need to be made based on fields that may change when 
//      contacts are inserted, edited, deleted and undeleted
//  
//  Created by:
//      Andrew Telford
//
//  Date: 
//      2015-08-17
//
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------

trigger CI_Trigger_Contact on Contact ( after insert, after update, before update, after delete, after undelete) 
{

//	Let us prepare some common variables
//----------------------------------------------------------------------------------------------
system.debug('Set the variables');

	// Common items
	STRING thisContactID;
	STRING thisContactOwnerID;
	STRING userID;
	STRING userProfileID;
	STRING errMsg = '';


//--	Let us get the details relating to this contact change
//----------------------------------------------------------------------------------------------
system.debug('Contact[]');

//--	Set the details of the trigger to a variable for use through the trigger
//----------------------------------------------------------------------------------------------
	Contact[] strContact;

	if (Trigger.isDelete) 
	{	strContact = Trigger.old;	}
	else
	{	strContact = Trigger.new;	}

	Set<ID> contactID = new Set<ID>();
	Set<ID> ownerIds = new Set<ID>();
	for(Contact objCont: strContact)
	{	ownerIds.add(objCont.ownerId);	}

    //--	For Owner Change Approved
	//----------------------------------------------------------------------------------------------
	LIST<Contact> contsToUpdate = [SELECT Id, OwnerId, Approved_Owner_Change__c, Approved_Owner_Name__c FROM Contact WHERE Id IN :strContact AND Approved_Owner_Change__c = TRUE];

    //--	For Magic Movers
	//----------------------------------------------------------------------------------------------
    LIST<User> thisOwner = [Select Id FROM User WHERE ID IN :ownerIds];
//-- Line 60 is below
    LIST<Contact> thisCount = [SELECT Id FROM Contact WHERE OwnerId IN :ownerIds AND CCC_Adviser__c = TRUE];

	FOR(Contact objCont: strContact)
	{

	//----------------------------------------------------------------------------------------------
	//----------------------------------------------------------------------------------------------
	//
	//  Owner Change Approved
	//
	//
	//

	//--	Define any variables required
	//----------------------------------------------------------------------------------------------
		system.debug('Set the variable values');
		BOOLEAN approvedOwnerChange;
		STRING newContactID = '';

	//--	Assign Values to Variables
	//----------------------------------------------------------------------------------------------
		contactID.add(objCont.Id);
		thisContactID = objCont.Id;
		thisContactOwnerID = objCont.OwnerId;
		userID = userinfo.getUserId();
		userProfileID = userinfo.getProfileId();
		approvedOwnerChange = objCont.Approved_Owner_Change__c;


	//--	Check to see if we are updating the owner
	//----------------------------------------------------------------------------------------------
		system.debug('Owner is to change');
		if( TRIGGER.isupdate && objCont.Approved_Owner_Change__c )
		{

	//--	Set the update list
	//----------------------------------------------------------------------------------------------
			List<Contact> updateOwner = new List<Contact>();

			FOR (Contact cont: contsToUpdate)
			{
				Boolean alterOwner = FALSE;

				IF ( cont.Approved_Owner_Change__c )
				{
					cont.OwnerID = cont.Approved_Owner_Name__c;
					cont.Approved_Owner_Change__c = FALSE;
					newContactID = cont.Approved_Owner_Name__c;
					updateOwner.add(cont);
				}
			}


	//--	Execute the update
	//----------------------------------------------------------------------------------------------
			if (!updateOwner.isEmpty()) 
			{
				try{ update updateOwner; }
				catch (Exception ex)
				{ System.debug('Could not update New Contact Owner [' + newContactID + '] cause: ' + ex.getCause() + 'APEX TRIGGER: CI_Trigger_Contact');}
			}
		}

	//
	//  End Approve Owner Change
	//
	//--------------------------------------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------------------------------------


	//--------------------------------------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------------------------------------
	//
	//  Magic Movers
	//
	//	This works in conjunction with:
	//		Validations
	//			Magic Mover Addition (03dc00000009014)
	//			Magic Mover REmoval (03dc00000009080)
	//
	//		Workflow Field Update
	//			New Contact (01Q20000000Es9Z)
	//			Set Magic Mover to False (04Yc000000090G1)
	//
	//
	//

	//--	Magic Movers 
	//------------------------------------------------------------------------------------------------------------------------------
		IF ( TRIGGER.isAfter )
        {
            BOOLEAN magicMover;
			DECIMAL userMagicCount;

	//--	Select the Owner Information
	//------------------------------------------------------------------------------------------------------------------------------
            system.debug( 'Size of thisUser: ' + thisOwner.size());
            LIST<User> updateUser = new LIST<User>();

            for ( User o1: thisOwner )
            {
                o1.Magic_Movers_Count__c = thisCount.size();
                updateUser.Add(o1);

            }	//--	For Owner Loop
	//--	Process the updates
	//------------------------------------------------------------------------------------------------------------------------------
                system.debug('size of: ' + updateuser.size());
                if (!updateUser.isEmpty()) 
                {
                    try{ update updateUser; }
                    catch (Exception ex)
                    { objCont.addError(' Error Updating ' + ex.getCause()); System.debug('Could not update User [' + thisContactOwnerID + '] cause: ' + ex.getCause() + 'APEX TRIGGER: CI_Trigger_Contact'); }
                }
        }	//--	End Check for After          

	//
	//  End Magic Movers
	//
	//--------------------------------------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------------------------------------
		//objCont.addError(errMsg);
	}

//
//  End Contact Loop
//
//--------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------
}

 
Hello Every one,

When ever i run the Test class i get the following Error "System.LimitException: Too many callouts: 101"
It happens only in test Class ,but when i run the job anomusly it will handle 400 records.

I am  struck badly can you please help me out


@isTest(Seealldata=true)
private class GlobalComplaintWebSvcCalloutTest {
   
    @isTest static   void testEchoString() {  
       String batchID;
       
         string ReadyForSAP= 'Ready For SAP';
        GlobalComplaintOutbound outbound= new GlobalComplaintOutbound();
       
         Test.setMock(WebServiceMock.class, new GlobalComplaintOutbountTest());
      // Test.startTest();
      hiGcsQncreateQncreateresponse.Response_element res= new  hiGcsQncreateQncreateresponse.Response_element();
       
       List<Case> scope = new List<Case>();
       List<case> caseQuery= new List<Case>();
      
       
       case CaseList= new Case();
       
      Database.BatchableContext BC;
         GLIntegrationAuthenticationSettings__c GLIntegration = GLIntegrationAuthenticationSettings__c.getAll().get('BizTalk');
      outbound.start(BC);
       outbound.execute(BC, scope);

Mock Class

global class GlobalComplaintOutbountTest implements WebServiceMock {
  
    global void doInvoke(
           Object stub,
           Object request,
           Map<String, Object> response,
           String endpoint,
           String soapAction,
           String requestName,
           String responseNS,
           String responseName,
           String responseType) {
                 wwwHollisterComGcsQncreate.BasicHttpBinding_ITwoWayAsync respElement= new wwwHollisterComGcsQncreate.BasicHttpBinding_ITwoWayAsync();
       hiGcsQncreateQncreaterequest.QN_element Request1= new hiGcsQncreateQncreaterequest.QN_element();
        GLIntegrationAuthenticationSettings__c GLIntegration = GLIntegrationAuthenticationSettings__c.getAll().get('BizTalk');
        hiGcsQncreateQncreateresponse.QNCreateResponse_element res = new hiGcsQncreateQncreateresponse.QNCreateResponse_element();
        hiGcsQncreateQncreateresponse.Response_element response_Element= new  hiGcsQncreateQncreateresponse.Response_element();
        hiGcsQncreateQncreaterequest.complainantInfo_element complainantInfo_element= new hiGcsQncreateQncreaterequest.complainantInfo_element();
        hiGcsQncreateQncreaterequest.complaintInfo_element  complaintInfo_element= new hiGcsQncreateQncreaterequest.complaintInfo_element();
        hiGcsQncreateQncreaterequest.productInfo_element productInfo_element= new hiGcsQncreateQncreaterequest.productInfo_element();
        hiGcsQncreateQncreaterequest.QN_element  QN_Element= new hiGcsQncreateQncreaterequest.QN_element();
        List<hiGcsQncreateQncreaterequest.QN_element> QN_List= new List<hiGcsQncreateQncreaterequest.QN_element>();
        hiGcsQncreateQncreaterequest.qnInfo_element qnInfo_element= new hiGcsQncreateQncreaterequest.qnInfo_element();
        hiGcsQncreateQncreaterequest.QNSet_element QNSet_element= new hiGcsQncreateQncreaterequest.QNSet_element();
        hiGcsQncreateQncreateresponse.QNCreateResponse_element c= new  hiGcsQncreateQncreateresponse.QNCreateResponse_element();
      
               
        // wwwHollisterComGcsQncreate
        wwwHollisterComGcsQncreate.BasicHttpBinding_ITwoWayAsync BasicHttpBinding_ITwoWayAsync = new wwwHollisterComGcsQncreate.BasicHttpBinding_ITwoWayAsync();
        QN_Element.qnInfo=qnInfo_element;
         QN_Element.productInfo=productInfo_element;
         QN_Element.complaintInfo=complaintInfo_element;
         QN_List.add(QN_Element);
         QNSet_element.QN=QN_List;

        //BasicHttpBinding_ITwoWayAsync.opQNCreate(QN_List);
        respElement.endpoint_x = 'https://diid.hollister.com/QNCreateWcfService/QNCreateService.svc';
        hiGcsQncreateQncreateresponse.Response_element response_x= respElement.opQNCreate(QN_List);
         
        
             if(response_x!=null)
             {
                   Database.executeBatch(new GlobalComplaintOutbound(), 1);
           response.put('response_x', response_x);
                 }
             
               
           }
               
   }
thanks for help in advance 

Regards,
Jyo

 
I have a javascript button that launches a visual force page, that allows an opportunity to be populated. 

I would like to be able to populate the case field (lookup field on opportunity) with the id of the case when the button is clicked (from the case object). I'm not sure if the best method is to ammend the javascript or the visualforce page. 

Any thoughts would be greatly appreciated.