• Dominic Blythe 18
  • NEWBIE
  • 55 Points
  • Member since 2014

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 15
    Replies
I've created a trigger to create child objects when a lookup field is changed on the parent object.  Instance: Parent Object =Laptop__c; Child object=Laptop_Update__c; Field=Location__c(Account). I was able to create and deploy successfully a trigger and class based upon creating a new Laptop and triggering the creatiion of the laptop updates, but when attempting to create a similar trigger and class based on information update on Laptop__c I ran into issues. Any assistance is appreciated.

Trigger:

trigger CreateIHSLaptopUpdate2 on Laptop__c (after Update) {
    List<IHS_Laptop_Updates__c> Updates = new List<IHS_Laptop_Updates__c>();
  
    //For each Laptop processed by the trigger, add a new
    //Update record for the specified user.
    //Note that Trigger.New is a list of all new Laptops
    //That are being created.
  
    for (Laptop__c updatedLaptop: Trigger.New) {
        if(updatedLaptop.Location__c !='0017000000bSTpd')
        if(updatedLaptop.Location__c !='0017000000YRiPy'){
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'AEP Software',
                Version__c = '2.36B ALI',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'IHS Auto Software Update',
                Version__c = '1.55',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'Central Internet Site',
                Version__c = 'N/A',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'Manual',
                Version__c = '2.32',
                IHS_Laptop__c = updatedLaptop.Id));
        }
    }

    insert Updates;
}

Test Class:

@IsTest
private class TestTrigger3 {

    static testmethod void testtrigger() {
   
        //Add Account
        Account A = new Account();
            A.Name = 'Test';
           
        insert A;
   
        //Add Laptop
        Laptop__c L = new Laptop__c();
            L.Name = 'Test';
       
        insert L;
       
        //Update Laptop
            L.Location__c = a.id;
        update L;
    }
}
Strange problem here. I have a trigger that does a simple SOQL query to retrieve an Event by its ID, e.g.:
List<sObject> theRecords = [select Id from Event where id = '00UC000000Pyy6c'];
It usually works with no problems. However when multiple contacts are added to the event and it becomes a shared activity, suddenly the query comes up empty when run in the trigger, even under a sysadmin profile.  Yet the same exact query is successful when run in SoqlXplorer, and when the code is executed using anonymous apex.

Any ideas for what might be going on? Does changing the Event to a shared activity with multiple contacts somehow change its ability to be queried via its ID?  

Thanks.
public Example(ApexPages.StandardController stdController)
WHY WE ARE WRITING THE CONSTRUCTOR LIKE THIS WANTS THE DETAIL PRESCRIPTION
I've created a trigger to create child objects when a lookup field is changed on the parent object.  Instance: Parent Object =Laptop__c; Child object=Laptop_Update__c; Field=Location__c(Account). I was able to create and deploy successfully a trigger and class based upon creating a new Laptop and triggering the creatiion of the laptop updates, but when attempting to create a similar trigger and class based on information update on Laptop__c I ran into issues. Any assistance is appreciated.

Trigger:

trigger CreateIHSLaptopUpdate2 on Laptop__c (after Update) {
    List<IHS_Laptop_Updates__c> Updates = new List<IHS_Laptop_Updates__c>();
  
    //For each Laptop processed by the trigger, add a new
    //Update record for the specified user.
    //Note that Trigger.New is a list of all new Laptops
    //That are being created.
  
    for (Laptop__c updatedLaptop: Trigger.New) {
        if(updatedLaptop.Location__c !='0017000000bSTpd')
        if(updatedLaptop.Location__c !='0017000000YRiPy'){
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'AEP Software',
                Version__c = '2.36B ALI',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'IHS Auto Software Update',
                Version__c = '1.55',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'Central Internet Site',
                Version__c = 'N/A',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'Manual',
                Version__c = '2.32',
                IHS_Laptop__c = updatedLaptop.Id));
        }
    }

    insert Updates;
}

Test Class:

@IsTest
private class TestTrigger3 {

    static testmethod void testtrigger() {
   
        //Add Account
        Account A = new Account();
            A.Name = 'Test';
           
        insert A;
   
        //Add Laptop
        Laptop__c L = new Laptop__c();
            L.Name = 'Test';
       
        insert L;
       
        //Update Laptop
            L.Location__c = a.id;
        update L;
    }
}
Hello everyone,

I have an After Update trigger on the Task object that creates a custom object record called a "Related Activity" for all the accounts related to the Task's account.

So for example, if an account called Diet Coke has a parent called Coca Cola and two siblings called Coke Zero and Dasani, then the new task under Diet Coke should show up as a Related Activity under Coca Cola, Coke Zero, and Dasani.

Anywho, I'm trying to use this trigger to mass update all our existing completed tasks (over 300,000 tasks) in batches of 200. The problem? Some of the batches seem to be going way over the "heap" limit, which I never knew about until now.

I'm still pretty confused on what will cause a "heap" issue, so can someone be kind enough to let me know which sections of my trigger might be causing the issue, and perhaps how to go about fixing it? Let me know if you need any additional info from me!

public class ClassRelatedActivities{
    
    public void addRelatedActivities(List<Task> tasks,Map<ID,Task> oldTasks){
        
        Set<String> accountsInTrigger = new Set<String>();
        Set<String> contactsInTrigger = new Set<String>();
        Set<String> parentSet = new Set<String>();
        Set<String> clientSet = new Set<String>();
        Set<String> agencySet = new Set<String>();
        Set<String> siblingAccounts = new Set<String>();
        
        Map<String,String> contactMap = new Map<String,String>();
        Map<String,String> parentMap = new Map<String,String>();
        Map<String,String> siblingParentMap = new Map<String,String>();
        Map<String,String> clientAgencyMap = new Map<String,String>();
        Map<String,String> agencyClientMap = new Map<String,String>();
        
        List<Related_Activity__c> relatedActivitiesToAdd = new List<Related_Activity__c>();
        
        
        
        FOR(Task t : tasks){
            IF(t.Mass_Update__c == TRUE && oldTasks.get(t.Id).Mass_Update__c != TRUE){
                IF(t.WhatId != NULL && string.valueOf(t.WhatId).startsWith('001')){
                    accountsInTrigger.add(t.WhatId);
                }
                ELSE IF(t.WhatId == NULL && t.WhoId != NULL && string.valueOf(t.WhoId).startsWith('003')){
                        contactsInTrigger.add(t.WhoId);
                    }
                }
        }
        
        
        
        FOR(Contact c : [SELECT
                        	Id,AccountId
                         FROM
                        	Contact
                         WHERE
                         	Id In :contactsInTrigger]){
                             
                                 contactMap.put(c.Id,c.AccountId);
                                 accountsInTrigger.add(c.AccountId);
                             
                         	}
        
        
        List<Account> childAccounts = [SELECT 
                                          Id, ParentId
                                       FROM 
                                          Account
                                       WHERE
                                          ParentId In :accountsInTrigger];
        
        FOR(Account pa : [SELECT
                             Id,ParentId
                          FROM
                             Account
                          WHERE
                          	 ParentId != NULL
                          AND
                          	 Id In :accountsInTrigger]){
                                 
                              			parentMap.put(pa.Id,pa.ParentId);
                              			parentSet.add(pa.ParentId);
                          }
        
        FOR(Account fc : [SELECT
                             Id, ParentId
                          FROM
                             Account
                          WHERE
                          	 ParentId In :parentSet]){
                              
                              	siblingParentMap.put(fc.Id,fc.ParentId);
                              	siblingAccounts.add(fc.Id);
                              
                          	}
        
        List<Client_Agency_Relationship__c> clientAgencies = [SELECT
                                                                Id,Client__c,Agency__c
                                                             FROM
                                                                Client_Agency_Relationship__c
                                                             WHERE
                                                                Client__c In :accountsInTrigger
                                                              OR
                                                                Agency__c In :accountsInTrigger];
        
        
            
        FOR(Task t0 : tasks){
            
            String accountID0;
                
                	IF(t0.WhatId != NULL){
                          accountID0 = t0.WhatId;
                    }
                                        
                    ELSE IF(t0.WhatId == NULL && t0.WhoId != NULL){
                          accountID0 = contactMap.get(t0.WhoId);
                    }
        
            FOR(Account a : childAccounts){
                
                IF(a.ParentId == accountID0){
                    
                    Related_Activity__c ra0 = new Related_Activity__c();
                    
                    IF(t0.Subject.length() > 80){
                        ra0.Name = t0.Subject.SubString(0,80);
                    }
                    ELSE{
                        ra0.Name = t0.Subject;
                    }
                    
                        ra0.Date__c = t0.ActivityDate;
                        ra0.Description__c = t0.Description;
                        ra0.Assigned_To__c = t0.OwnerId;
                        ra0.Activity_ID__c = t0.Id;
                        ra0.Name__c = t0.WhoId;
                        ra0.Relationship__c = 'Parent';
                        ra0.Account__c = a.Id;
                        ra0.Related_To__c = accountID0;
                
                    relatedActivitiesToAdd.add(ra0);
                    
                }
                
            }
       
        }
        
        
            
            FOR(Task t1 : tasks){
                
                String accountID1;
                String parentID1;
                
                	IF(t1.WhatId != NULL){
                          accountID1 = t1.WhatId;
                          parentID1 = parentMap.get(t1.WhatId);
                    }
                                        
                    ELSE IF(t1.WhatId == NULL && t1.WhoId != NULL){
                          accountID1 = contactMap.get(t1.WhoId);
                          parentID1 = parentMap.get(contactMap.get(t1.WhoId));
                    }
                
                FOR(String a1 : siblingAccounts){
                    
                    IF(siblingParentMap.get(a1) == parentID1 && a1 != accountID1){
                    
                    Related_Activity__c ra1 = new Related_Activity__c();
                        
                        IF(t1.Subject.length() > 80){
                            ra1.Name = t1.Subject.SubString(0,80);
                        }
                        ELSE{
                            ra1.Name = t1.Subject;
                        }
                        
                    ra1.Date__c = t1.ActivityDate;
                    ra1.Description__c = t1.Description;
                    ra1.Assigned_To__c = t1.OwnerId;
                	ra1.Activity_ID__c = t1.Id;
                    ra1.Name__c = t1.WhoId;
                    ra1.Relationship__c = 'Sibling';
                    ra1.Account__c = a1;
                    ra1.Related_To__c = accountID1;
                    
                    relatedActivitiesToAdd.add(ra1);
                        
                    }
                }
            }
        
        
        
        FOR(Task t2 : tasks){
            
            String accountID2;
                
                	IF(t2.WhatId != NULL){
                          accountID2 = t2.WhatId;
                    }
                                        
                    ELSE IF(t2.WhatId == NULL && t2.WhoId != NULL){
                          accountID2 = contactMap.get(t2.WhoId);
                    }
        
            FOR(Client_Agency_Relationship__c car0 : clientAgencies){
                
                IF(car0.Agency__c == accountID2){
                
                    Related_Activity__c ra2 = new Related_Activity__c();
                    
                    IF(t2.Subject.length() > 80){
                        ra2.Name = t2.Subject.SubString(0,80);
                    }
                    ELSE{
                        ra2.Name = t2.Subject;
                    }
                    
                    ra2.Date__c = t2.ActivityDate;
                    ra2.Description__c = t2.Description;
                    ra2.Assigned_To__c = t2.OwnerId;
                    ra2.Activity_ID__c = t2.Id;
                    ra2.Name__c = t2.WhoId;
                    ra2.Relationship__c = 'Agency';
                    ra2.Account__c = car0.Client__c;
                    ra2.Related_To__c = accountID2;
                
                    relatedActivitiesToAdd.add(ra2);
                    
                }
            }
    }
        
        
        
        FOR(Task t3 : tasks){
            
            String accountID3;
                
                	IF(t3.WhatId != NULL){
                          accountID3 = t3.WhatId;
                    }
                                        
                    ELSE IF(t3.WhatId == NULL && t3.WhoId != NULL){
                          accountID3 = contactMap.get(t3.WhoId);
                    }
        
            FOR(Client_Agency_Relationship__c car1 : clientAgencies){
                
                IF(car1.Client__c == accountID3){
                
                    Related_Activity__c ra3 = new Related_Activity__c();
                    
                    IF(t3.Subject.length() > 80){
                        ra3.Name = t3.Subject.SubString(0,80);
                    }
                    ELSE{
                        ra3.Name = t3.Subject;
                    }
                    
                    ra3.Date__c = t3.ActivityDate;
                    ra3.Description__c = t3.Description;
                    ra3.Assigned_To__c = t3.OwnerId;
                    ra3.Activity_ID__c = t3.Id;
                    ra3.Name__c = t3.WhoId;
                    ra3.Relationship__c = 'Client';
                    ra3.Account__c = car1.Agency__c;
                    ra3.Related_To__c = accountID3;
               
                    relatedActivitiesToAdd.add(ra3);
                    
                }
            }
    }
        
        
        
        FOR(Task t4 : tasks){
            
            String accountID4;
            String parentID4;
                
                	IF(t4.WhatId != NULL){
                          accountID4 = t4.WhatId;
                          parentID4 = parentMap.get(t4.WhatId);
                    }
                                        
                    ELSE IF(t4.WhatId == NULL && t4.WhoId != NULL){
                          accountID4 = contactMap.get(t4.WhoId);
                          parentID4 = parentMap.get(contactMap.get(t4.WhoId));
                    }
        
            FOR(String a4 : parentSet){
                
                IF(parentID4 == a4){
                
                    Related_Activity__c ra4 = new Related_Activity__c();
                    
                    IF(t4.Subject.length() > 80){
                        ra4.Name = t4.Subject.SubString(0,80);
                    }
                    ELSE{
                        ra4.Name = t4.Subject;
                    }
                    
                    ra4.Date__c = t4.ActivityDate;
                    ra4.Description__c = t4.Description;
                    ra4.Assigned_To__c = t4.OwnerId;
                    ra4.Activity_ID__c = t4.Id;
                    ra4.Name__c = t4.WhoId;
                    ra4.Relationship__c = 'Child';
                    ra4.Account__c = a4;
                    ra4.Related_To__c = accountID4;
               
                    relatedActivitiesToAdd.add(ra4);
                    
                }
        }
    }
           
        
        IF(relatedActivitiesToAdd.size() > 0){
        	INSERT relatedActivitiesToAdd;
        }
        
    }

}

Thanks!
-Greg
to get Google Charts (Donut, Area) from a Visual force page to a PDF.
It works fine on the Visual force page but when we render that page as PDF the charts are not getting displayed on the PDF Page.
Kindly suggest us with a solution to achieve this functionality.
I have a cusom page using the standard controller for a custom object.  I am passing in two fields in the URL invocation, and I simply want to Validate/Save the record and return (avoiding a user-initiated Save action).  How should I configure the apex page or form elements to accomplish that.
Hello Guys

Again Stuck with the concatenation :

private final String SOQL_RECENT_REC = 'SELECT LastViewedDate,Type,UserRoleId FROM RecentlyViewed';
private final String CONDITION_USER_SORT = ' Order By LastViewedDate DESC LIMIT 20';
List<RecentlyViewed> recentViewed= new List<RecentlyViewed>();
recentViewed = Database.query(SOQL_RECENT_REC +' WHERE Type = \'Account \' ' + CONDITION_USER_SORT);

Should run a query like the following :
recentViewed = [SELECT LastViewedDate,Type,UserRoleId FROM RecentlyViewed Where Type='Account' Order By LastViewedDate DESC LIMIT 20];

Many Thanks !!
Hi,
How can i create a one to many relationship between a campaign and campaign members? The setup is as follows: whenever a lead or contact is added to a campaign, it is considered a campaign member. I want to be able to check if a particular lead or contact is a campaign member already. If not, then I want to make it a campaign member of a campaign when a certain criteria is met.

how can I do this in an apex class/trigger?
Strange problem here. I have a trigger that does a simple SOQL query to retrieve an Event by its ID, e.g.:
List<sObject> theRecords = [select Id from Event where id = '00UC000000Pyy6c'];
It usually works with no problems. However when multiple contacts are added to the event and it becomes a shared activity, suddenly the query comes up empty when run in the trigger, even under a sysadmin profile.  Yet the same exact query is successful when run in SoqlXplorer, and when the code is executed using anonymous apex.

Any ideas for what might be going on? Does changing the Event to a shared activity with multiple contacts somehow change its ability to be queried via its ID?  

Thanks.
I've created a permission set in my development sandbox and successfully deployed it to another sandbox usiing Change Sets. However none of the change set's configuration was retained in the new environment. None of the objects' checkboxes remained selected, meaning no object level or page level access for my users. How is it possible for the premission set to deploy successfully but none of its settings are retained?

Thank you!
I am trying to test a web service callout from Salesforce to a PHP web service but I am getting this error and I am struggling to find a solution.

This is the WSDL file (http://www.popo.it/WebServiceSOAP/server.php?wsdl) that has been imported in SF with WSDL2APEX.
The generated class is

//Generated by wsdl2apex

public class wsexample {
    public class helloRequestType {
        public String name;
        private String[] name_type_info = new String[]{'name','urn:server',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:server','true','false'};
        private String[] field_order_type_info = new String[]{'name'};
    }
    public class wsexamplePort {
        public String endpoint_x = 'http://www.popo.it/WebServiceSOAP/server.php';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'urn:server', 'wsexample'};
        public String hello(String name) {
            wsexample.helloRequestType request_x = new wsexample.helloRequestType();
            wsexample.helloResponseType response_x;
            request_x.name = name;
            Map<String, wsexample.helloResponseType> response_map_x = new Map<String, wsexample.helloResponseType>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'urn:server#hello',
              'urn:server',
              'hello',
              'urn:server',
              'helloResponse',
              'wsexample.helloResponseType'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }
    }
    public class helloResponseType {
        public String return_x;
        private String[] return_x_type_info = new String[]{'return','urn:server',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:server','true','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
}

And the VF page using it is

<apex:page controller="WSContoller" tabStyle="Account">
It will be a nice to get output from the controller
<p>My webservice is now returning {!HelloWorld} !!</p>
</apex:page>

with controller

public class WSContoller {

public String helloWorld;

public String getHelloWorld() {
    string MyReturn;
    wsexample.wsexamplePort stub = new wsexample.wsexamplePort();
    MyReturn = stub.hello('Nicola');
    return MyReturn ;
    }
   
}

The response from the WS tested in SoapClient.com is

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<helloResponse>
<great>Hello, Nicola!</great>
</helloResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Please, can you help me to find the error?

Hello everyone,

I made a thread on here a few weeks ago about how I couldn't deploy a new trigger, because a previous 'After' trigger I deployed was causing too many SOQL queries in my new 'Before' trigger.

Anywho, a fine gentleman on here told me I needed to check the aforementioned 'After' trigger for recursion, so that it wouldn't run more than once. That allowed me to deploy the new 'Before' trigger.

So what is the problem now? That 'After' trigger that I'm checking for recursion....it doesn't work anymore. I only checked today to see if it was still working, but it seems it hasn't been working since I made that change to the code. When I remove the recursion check and test out the trigger in the sandbox, it works again.

Why do I think this is? Because the purpose of that 'After' trigger is to update another opportunity (the same object). I'm assuming it won't work if it only runs once. Perhaps I have to run it twice? If so, how can I make that change? Please keep in mind that I'm still a newb to coding.


Here is the class I'm using to check for recursion:

public Class checkRecursive{
   
    private static boolean run = true;
   
    public static boolean runOnce(){
       
    if(run){
     run=false;
     return true;  
    }
    else{
        return run;
    }
       
    }
}




Here is the trigger that no longer works:

trigger RenewalProcess on Opportunity (after insert, after update) {
   
     if(checkRecursive.runOnce()){
   
   Set<String> allOpps = new Set<String>();
    for(Opportunity renewalOpp : Trigger.new) {
        if (renewalOpp.Renewed_Opportunity__c != null) {
            allOpps.add(renewalOpp.Renewed_Opportunity__c);
          }
    }

    List<Opportunity> potentialOpps = [SELECT Id FROM Opportunity WHERE Id IN :allOpps];

    Map<String,Opportunity> opportunityMap = new Map<String,Opportunity>();
        for (Opportunity o : potentialOpps) {
            opportunityMap.put(o.id,o);
        }
   
    List<Opportunity> firstOppsToUpdate = new List<Opportunity>();

        for (Opportunity renewalOpp : Trigger.new) {
             if (renewalOpp.Renewed_Opportunity__c != null) {
             Opportunity renewedOpp = opportunityMap.get(renewalOpp.Renewed_Opportunity__c);
             renewedOpp.Renewal_Process_Checkbox__c = TRUE;
             firstOppsToUpdate.add(renewedOpp);
           }
           
        }

    update firstOppsToUpdate;
     
     List<Opportunity> oppsToUpdate = new List<Opportunity>();
       
        for (Opportunity renewalOpp : Trigger.new) {
            if (renewalOpp.Renewed_Opportunity__c != null && renewalOpp.StageName.equals('Closed Won')) {
                Opportunity renewedOpp = opportunityMap.get(renewalOpp.Renewed_Opportunity__c);
                renewedOpp.Renewal_Status__c = 'Renewed';
                oppsToUpdate.add(renewedOpp);
            }
            else if(renewalOpp.Renewed_Opportunity__c != null && !renewalOpp.IsClosed) {
                Opportunity renewedOpp = opportunityMap.get(renewalOpp.Renewed_Opportunity__c);
                renewedOpp.Renewal_Status__c = 'In Negotiations';
                oppsToUpdate.add(renewedOpp);
            }
            else if(renewalOpp.Renewed_Opportunity__c != null && (renewalOpp.StageName.equals('Closed Lost') || renewalOpp.StageName.equals('Closed Stalled'))) {
                Opportunity renewedOpp = opportunityMap.get(renewalOpp.Renewed_Opportunity__c);
                renewedOpp.Renewal_Status__c = 'Did Not Renew';
                oppsToUpdate.add(renewedOpp);
            }
           
        }
   
    update oppsToUpdate;
        
     }
   
}



Let me know if you need any other info from me!

Thanks,
Greg