• Tatiana B Cooke
  • NEWBIE
  • 10 Points
  • Member since 2016
  • Salesforce Administrator
  • Howard Hughes Corporation

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
I am simply trying to copy and past the code pardot gave me into my sandbox.

Instructions they provided:  http://help.pardot.com/customer/portal/articles/2127277-setting-up-salesforce-person-accounts-for-pardot-syncing

Getting the following error right off the bat. 

Error: Compile Error: Invalid type: pi__ObjectChangeLog__c at line 3 column 48


Please help!
trigger LogPersonAccountChange on Account (before delete, after insert, after undelete)
{
  List<pi__ObjectChangeLog__c> logs = new List<pi__ObjectChangeLog__c>(); 

  if (Trigger.new != null) {
    for (Account account : Trigger.new) {

      if (Account.PersonEmail != null && Account.PersonEmail != '') {
        pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c();
        log.pi__ObjectFid__c = Account.PersonContactId;
        log.pi__ObjectType__c = 1;
        log.pi__ObjectEmail__c = Account.PersonEmail;

        if  (System.Trigger.isInsert) {
          log.pi__ObjectState__c = 1;
        } else if  (System.Trigger.isDelete) {
          log.pi__ObjectState__c = 2;
        } else if  (System.Trigger.isUnDelete) {
          log.pi__ObjectState__c = 3;

        }
        logs.add(log);
      }
    }
  } else if (Trigger.old != null) {
    for (Account account : Trigger.old) {
      if (Account.PersonEmail != null && Account.PersonEmail != '') {
        pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c();

        log.pi__ObjectFid__c = Account.PersonContactId

        ;
        log.pi__ObjectType__c = 1;
        log.pi__ObjectEmail__c = Account.PersonEmail;
        if  (System.Trigger.isInsert) {
          log.pi__ObjectState__c = 1;
        } else if  (System.Trigger.isDelete) {
          log.pi__ObjectState__c = 2;
        } else if  (System.Trigger.isUnDelete) {
          log.pi__ObjectState__c = 3;
        }
        logs.add(log);
      }
    }
  }

  if (logs.size() > 0) {

    insert logs;
  }
}




 
Getting Error when trying to blank out a Lookup field once a trigger has run to insert Opportunity Team Member.Below is a trigger I wrote to create an Opportunnity Team Member when a lookup field called Secondary Owner is updated. The issue is when I try and blank out the lookup (Say if the secondary owner was input incorrectly) I get the following error. 
 
Error: Apex trigger OTOpportunityTrigger caused an unexpected exception, contact your administrator: OTOpportunityTrigger: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [User]: [User]: Trigger.OTOpportunityTrigger: line 13, column 1

Below is my trigger
trigger OTOpportunityTrigger on Opportunity (before update) {
    List<OpportunityTeamMember> listOpptyTeamMem = new List<OpportunityTeamMember>();
    
    for(Opportunity oppty : trigger.New){
        OpportunityTeamMember OTM = new OpportunityTeamMember();
        OTM.OpportunityId = oppty.Id;
        OTM.TeamMemberRole = 'Secondary Owner'; 
        OTM.UserId = oppty.Secondary_Owner__c;
        listOpptyTeamMem.add(OTM);   
        
       
            if(listOpptyTeamMem.size() > 0){
        insert listOpptyTeamMem;
       
         
        // get all of the team members' sharing recordsPost to Community
        List<OpportunityShare> shares = [select Id, OpportunityAccessLevel, 
          RowCause from OpportunityShare where OpportunityId = :oppty.Id
          and RowCause = 'Team'];
 
        // set all team members access to read/write
        for (OpportunityShare share : shares) 
          share.OpportunityAccessLevel = 'Edit';
 
        update shares;
    }
}
}

and here is my test class
 
@isTest(SeeAllData=true)
public with sharing class TestOTOpportunityTrigger {

    public static testmethod void test_1() {
             
            //create test account
            Account a  = new Account();
            a.name     = 'Teston';
            insert a;

            //create test opportunity 
            
        Opportunity o  = new Opportunity();
        o.OwnerID = '005i0000004LFZH';
        o.Name = 'Test';
        o.AccountID = '001i000001mCGvY';
        o.Unit_Number__c = 'a01i000000YWLGK';
        o.Financing_Type__c = 'Cash Buyer';
        o.Nature_of_Tenancy__c = 'Severalty';
        o.Sale_Type__c = 'Founder';
        o.CloseDate = Date.today();
        o.stageName = 'S1: Ready to Contract';
        o.Secondary_Owner__c = '005i0000004LFZH';
        
        
        insert o;
        
        OpportunityTeamMember OTM = new OpportunityTeamMember();
        OTM.OpportunityId = o.Id;
        OTM.TeamMemberRole = 'Secondary Owner'; 
        OTM.UserId = o.Secondary_Owner__c;   
        

            
            insert OTM;
             
             
            List<OpportunityTeamMember> OTMs = [SELECT id, UserId, OPPORTUNITYACCESSLEVEL
                                                FROM OpportunityTeamMember
                                                WHERE OpportunityId =: otm.Id
                                                ];
         
             
             
            //update O to execute the trigger
            update otm;
             
            //re-query
            OTMs = [SELECT id, UserId, OPPORTUNITYACCESSLEVEL
                    FROM OpportunityTeamMember
                    WHERE OpportunityId =: otm.Id
                    ];
             

        }

    }

 
Team, 

New to the developer side of Salesforce. Need to know what the test class would be for the below Apex Class and Visualforce Page. Appreciate any help or guidance. When I tried pushing to production it tested ALL previous code and would not let mine thru. Any pointers there would help as well. 

This code involves having a custom attach button within a page layout on a standard object. 

Apex Class 
public class attachmentsample {

    public attachmentsample(ApexPages.StandardController controller) {

    }
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
   
    Public Pagereference Save()
    {
        String accid = System.currentPagereference().getParameters().get('id');

        Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
         
         /* insert the attachment */
         insert a;
        return NULL;
    }   

}

Visualforce Page

<apex:page standardController="Tenant_Coordination__c" extensions="attachmentsample">
    <apex:form >
    <apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" />
       <apex:commandbutton value="Save" action="{!Save}" onclick="window.top.location='/{!Tenant_Coordination__c.id}'; return true"/>
    </apex:form>
</apex:page>
Getting Error when trying to blank out a Lookup field once a trigger has run to insert Opportunity Team Member.Below is a trigger I wrote to create an Opportunnity Team Member when a lookup field called Secondary Owner is updated. The issue is when I try and blank out the lookup (Say if the secondary owner was input incorrectly) I get the following error. 
 
Error: Apex trigger OTOpportunityTrigger caused an unexpected exception, contact your administrator: OTOpportunityTrigger: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [User]: [User]: Trigger.OTOpportunityTrigger: line 13, column 1

Below is my trigger
trigger OTOpportunityTrigger on Opportunity (before update) {
    List<OpportunityTeamMember> listOpptyTeamMem = new List<OpportunityTeamMember>();
    
    for(Opportunity oppty : trigger.New){
        OpportunityTeamMember OTM = new OpportunityTeamMember();
        OTM.OpportunityId = oppty.Id;
        OTM.TeamMemberRole = 'Secondary Owner'; 
        OTM.UserId = oppty.Secondary_Owner__c;
        listOpptyTeamMem.add(OTM);   
        
       
            if(listOpptyTeamMem.size() > 0){
        insert listOpptyTeamMem;
       
         
        // get all of the team members' sharing recordsPost to Community
        List<OpportunityShare> shares = [select Id, OpportunityAccessLevel, 
          RowCause from OpportunityShare where OpportunityId = :oppty.Id
          and RowCause = 'Team'];
 
        // set all team members access to read/write
        for (OpportunityShare share : shares) 
          share.OpportunityAccessLevel = 'Edit';
 
        update shares;
    }
}
}

and here is my test class
 
@isTest(SeeAllData=true)
public with sharing class TestOTOpportunityTrigger {

    public static testmethod void test_1() {
             
            //create test account
            Account a  = new Account();
            a.name     = 'Teston';
            insert a;

            //create test opportunity 
            
        Opportunity o  = new Opportunity();
        o.OwnerID = '005i0000004LFZH';
        o.Name = 'Test';
        o.AccountID = '001i000001mCGvY';
        o.Unit_Number__c = 'a01i000000YWLGK';
        o.Financing_Type__c = 'Cash Buyer';
        o.Nature_of_Tenancy__c = 'Severalty';
        o.Sale_Type__c = 'Founder';
        o.CloseDate = Date.today();
        o.stageName = 'S1: Ready to Contract';
        o.Secondary_Owner__c = '005i0000004LFZH';
        
        
        insert o;
        
        OpportunityTeamMember OTM = new OpportunityTeamMember();
        OTM.OpportunityId = o.Id;
        OTM.TeamMemberRole = 'Secondary Owner'; 
        OTM.UserId = o.Secondary_Owner__c;   
        

            
            insert OTM;
             
             
            List<OpportunityTeamMember> OTMs = [SELECT id, UserId, OPPORTUNITYACCESSLEVEL
                                                FROM OpportunityTeamMember
                                                WHERE OpportunityId =: otm.Id
                                                ];
         
             
             
            //update O to execute the trigger
            update otm;
             
            //re-query
            OTMs = [SELECT id, UserId, OPPORTUNITYACCESSLEVEL
                    FROM OpportunityTeamMember
                    WHERE OpportunityId =: otm.Id
                    ];
             

        }

    }

 
Team, 

New to the developer side of Salesforce. Need to know what the test class would be for the below Apex Class and Visualforce Page. Appreciate any help or guidance. When I tried pushing to production it tested ALL previous code and would not let mine thru. Any pointers there would help as well. 

This code involves having a custom attach button within a page layout on a standard object. 

Apex Class 
public class attachmentsample {

    public attachmentsample(ApexPages.StandardController controller) {

    }
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
   
    Public Pagereference Save()
    {
        String accid = System.currentPagereference().getParameters().get('id');

        Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
         
         /* insert the attachment */
         insert a;
        return NULL;
    }   

}

Visualforce Page

<apex:page standardController="Tenant_Coordination__c" extensions="attachmentsample">
    <apex:form >
    <apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" />
       <apex:commandbutton value="Save" action="{!Save}" onclick="window.top.location='/{!Tenant_Coordination__c.id}'; return true"/>
    </apex:form>
</apex:page>