• Mike Parks 5
  • NEWBIE
  • 25 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies
This visualforce page works perfectly in Sandbox but when I copy it into Production, clicking the Save button shows a blank screen, even though the record actually gets created. It's like it won't re-render back to the newly created record for display. Has anybody seen anything like this? 

<apex:page standardController="Project__c" extensions="RelatedController1">
<apex:stylesheet value="/resources/htdocs/css/basic.css"/>
 <apex:form >
          <apex:outputpanel id="accinfo" > 
   <apex:pageMessages id="msgs"/>
   <apex:pageBlock title="Project Create/Edit">
   <apex:pageMessages ></apex:pageMessages>
           <apex:pageMessages id="showmsg"></apex:pageMessages>
       <apex:actionRegion >
            <apex:pageblocksection title="Information" showheader="true" columns="2">
             <apex:pageblocksection columns="1">
                    <apex:inputField value="{!Project__c.Proposal__c}">
                    <apex:actionSupport event="onchange" action="{!PopulateProject}" rerender="accinfo, msgs"/> 
                    </apex:inputField>
                 <apex:actionFunction name="CallApexMethod" action="{!PopulateProject}" reRender="accinfo, msgs"/>
                  <apex:inputField value="{!Project__c.Name}" />
                  <apex:inputField value="{!Project__c.Account__c}" />
                    <apex:inputField value="{!Project__c.Project_Contact__c}"/>
                    <apex:inputfield value="{!Project__c.Scope_of_Work__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.Service_Type__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.Project_Stage__c}" required="false"/>
             </apex:pageblocksection>                    
             <apex:pageblocksection columns="1">
                    <apex:inputfield value="{!Project__c.Contract_Date__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.Start_Date_Project__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.End_Date_Project__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.Substance_Code__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.Project_Manager__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.Co_Project_Manager__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.Co_Project_Manager1__c}" required="false"/>
             </apex:pageblocksection>
                </apex:pageblocksection>
                <apex:pageblocksection title="Financials" showheader="true" columns="1">
                <apex:inputfield value="{!Project__c.Person_Days__c}"/>
                <apex:inputfield value="{!Project__c.Corp_Size__c}"/>
                    <apex:inputfield value="{!Project__c.Travel_and_Expenses__c}" required="false"/>
                </apex:pageblocksection>
                <apex:pageblocksection title="PIF Required" showheader="true" columns="2">
                    <apex:inputfield value="{!Project__c.Delivery_Mode__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.Project_Mode_Type__c}" required="false"/>
                    <apex:inputfield value="{!Project__c.EIS_Years__c}" required="false"/>
                    <apex:pageblocksectionitem />
                </apex:pageblocksection>
      </apex:actionRegion>
      <apex:pageBlockButtons >
        <apex:commandButton value="Cancel" action="{!cancel}"/>
        <apex:commandButton value="Save" action="{!save}" reRender="showmsg"/>
      </apex:pageBlockButtons>
   </apex:pageBlock>
 </apex:outputpanel>
  </apex:form>
      <script>
    function addLoadEvent(func) 

  var oldonload = window.onload; 
  if (typeof window.onload != 'function') 
  { 
     window.onload = func; 
  } 
  else
  { 
      window.onload = function()  
      { 
        if (oldonload) 
        { 
           oldonload(); 
        } 
        func(); 
      } 
   } 

   
addLoadEvent(function()  


var controllervariable='{!Project__c.Proposal__c}';
if(controllervariable==null || controllervariable == ''){return false;}
else {
  
    CallApexMethod(); }
});

    </script>
</apex:page>

I've written a simple trigger which works fine in Sandbox. However my test class won't work at all and so I am unable to move my trigger into Production. I keep getting the error: "List has no rows for assignment to SObject" on the line Insert prj; in the test class shown below. I'm worried the SObject prj is empty because it requires a RecordType and I'm not creating/setting the RecordType correctly. All of the other Insert's in the Test Class work fine but they don't require RecordType.  
trigger UpdateRelatedGoal on Project__c (before insert) {

for (Project__c p : Trigger.New) {

 if(p.Start_Date_Project__c==Null ) {
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter a Project Start Date'));
        }

    sObject s = [SELECT Id FROM Goals__c WHERE Region_Name__c =:p.Region__c  AND Year__c =:p.Start_Year_Project__c  ];
  
   for(Project__c a : Trigger.New) {
        a.Goal__c = s.Id;
    }
 
    }  
}

Here's my Test Class so far.....
 
@isTest
private class TestUpdateRelatedGoal {
    @isTest static void TestGoalUpdateWithStartDate() {
    
// Create Project Manager
        Project_Manager__c pm = new Project_Manager__c(Name='mwp');
        insert pm;
// Create Account
        Account acct = new Account(Name='Acme');
        insert acct;
// Create Contact
        Contact cont = new Contact(FirstName='joe',LastName='blow1',email='joe@mail.com', title='president');
        insert cont;
// Create Proposal
       Proposal__c prop = new Proposal__c(Name='Test Proposal',Date__c=System.today(),Proposal_Estimate__c=1000, Contact__c=cont.Id, Service_Type__c='Other');
       insert prop;

// Create Project
    RecordType rt = [SELECT Id FROM RecordType WHERE SObjectType='Project__c' AND Name='Confirmation of Service' LIMIT 1];

    Project__c prj = new Project__c(Proposal__c=prop.Id,Start_Date_Project__c=System.today(),End_Date_Project__c=System.today(),Account__c=acct.Id,Project_Contact__c=cont.Id);

    prj.Name = 'test';
    prj.Service_Type__c='Other';
    prj.Substance_Code__c='33 Workforce';
    prj.Project_Manager__c=pm.Id;
    prj.Account__c=acct.Id;

        
        // Perform test
        Test.startTest();
         insert prj;                // This row is where error occurs
        Test.stopTest();

    }

}


 
Can anyone suggest how to approach writing a test class for this extension controller?

I have two custom objects, Proposal and Project where Proposal is a lookup from Project. PopulateProject method shown below is called from a VF page that overrides the New Project button so that whenever a Proposal__c related lookup has been selected it pulls a few fields from the selected Proposal__c record and populates them onto matching fields on the Project_c screen prior to the Project__c object being saved.

I've tried following the tutorials on writing test classes but can't find one that is close to my use case so I don't think I'm heading in the right direction. Any suggestions greatly appreciated. Or just a pointer to a similar example. Thanks in advance!     

public with sharing class RelatedController1
{
public Proposal__c prop {get;set;}

private ApexPages.StandardController stdCtrl;
  
 public RelatedController1(ApexPages.StandardController std)
 {
  stdCtrl=std;
 }
  
 public void PopulateProject()
 {
  Project__c proj=(Project__c) stdCtrl.getRecord();
if(proj.Proposal__c == null){return;}
else{
  prop=[select Name,  Account__c, Scope_of_Work__c, Contact__c from Proposal__c where Id=:proj.Proposal__c];
 
  proj.Name=prop.Name;
  proj.Account__c=prop.Account__c;
  proj.Scope_of_Work__c=prop.Scope_of_Work__c;
  proj.Project_Contact__c=prop.Contact__c;}
 }
}
I keep getting this error when I try to save the following code...any idea what I've got wrong? 

Error: Compile Error: Illegal assignment from List<Proposal__c> to Id at line 13 column 3


public with sharing class AnotherController
{
 private ApexPages.StandardController stdCtrl;
  
 public AnotherController(ApexPages.StandardController std)
 {
  stdCtrl=std;
 }
  
 public void PopulateProject()
 {
  Project__c proj=(Project__c) stdCtrl.getRecord();
  proj.Proposal__c=[select Scope_of_Work__c from Proposal__c where Id=:proj.Proposal__c];
  proj.Scope_of_Work__c=proj.Proposal__c.Scope_of_Work__c;
 }
}
I need to auto populate a field on a custom object after selecting a lookup field value and before saving the record. It's the exact same functionality seen on a new contact after selecting the related Account and the Account address auto populates the Contact address before saving. I've tried workflow field update and a trigger which both work fine AFTER saving the record. But I can't figure out how to make it work BEFORE saving the record. Thanks! 

I've written a simple trigger which works fine in Sandbox. However my test class won't work at all and so I am unable to move my trigger into Production. I keep getting the error: "List has no rows for assignment to SObject" on the line Insert prj; in the test class shown below. I'm worried the SObject prj is empty because it requires a RecordType and I'm not creating/setting the RecordType correctly. All of the other Insert's in the Test Class work fine but they don't require RecordType.  
trigger UpdateRelatedGoal on Project__c (before insert) {

for (Project__c p : Trigger.New) {

 if(p.Start_Date_Project__c==Null ) {
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter a Project Start Date'));
        }

    sObject s = [SELECT Id FROM Goals__c WHERE Region_Name__c =:p.Region__c  AND Year__c =:p.Start_Year_Project__c  ];
  
   for(Project__c a : Trigger.New) {
        a.Goal__c = s.Id;
    }
 
    }  
}

Here's my Test Class so far.....
 
@isTest
private class TestUpdateRelatedGoal {
    @isTest static void TestGoalUpdateWithStartDate() {
    
// Create Project Manager
        Project_Manager__c pm = new Project_Manager__c(Name='mwp');
        insert pm;
// Create Account
        Account acct = new Account(Name='Acme');
        insert acct;
// Create Contact
        Contact cont = new Contact(FirstName='joe',LastName='blow1',email='joe@mail.com', title='president');
        insert cont;
// Create Proposal
       Proposal__c prop = new Proposal__c(Name='Test Proposal',Date__c=System.today(),Proposal_Estimate__c=1000, Contact__c=cont.Id, Service_Type__c='Other');
       insert prop;

// Create Project
    RecordType rt = [SELECT Id FROM RecordType WHERE SObjectType='Project__c' AND Name='Confirmation of Service' LIMIT 1];

    Project__c prj = new Project__c(Proposal__c=prop.Id,Start_Date_Project__c=System.today(),End_Date_Project__c=System.today(),Account__c=acct.Id,Project_Contact__c=cont.Id);

    prj.Name = 'test';
    prj.Service_Type__c='Other';
    prj.Substance_Code__c='33 Workforce';
    prj.Project_Manager__c=pm.Id;
    prj.Account__c=acct.Id;

        
        // Perform test
        Test.startTest();
         insert prj;                // This row is where error occurs
        Test.stopTest();

    }

}


 
Can anyone suggest how to approach writing a test class for this extension controller?

I have two custom objects, Proposal and Project where Proposal is a lookup from Project. PopulateProject method shown below is called from a VF page that overrides the New Project button so that whenever a Proposal__c related lookup has been selected it pulls a few fields from the selected Proposal__c record and populates them onto matching fields on the Project_c screen prior to the Project__c object being saved.

I've tried following the tutorials on writing test classes but can't find one that is close to my use case so I don't think I'm heading in the right direction. Any suggestions greatly appreciated. Or just a pointer to a similar example. Thanks in advance!     

public with sharing class RelatedController1
{
public Proposal__c prop {get;set;}

private ApexPages.StandardController stdCtrl;
  
 public RelatedController1(ApexPages.StandardController std)
 {
  stdCtrl=std;
 }
  
 public void PopulateProject()
 {
  Project__c proj=(Project__c) stdCtrl.getRecord();
if(proj.Proposal__c == null){return;}
else{
  prop=[select Name,  Account__c, Scope_of_Work__c, Contact__c from Proposal__c where Id=:proj.Proposal__c];
 
  proj.Name=prop.Name;
  proj.Account__c=prop.Account__c;
  proj.Scope_of_Work__c=prop.Scope_of_Work__c;
  proj.Project_Contact__c=prop.Contact__c;}
 }
}
I keep getting this error when I try to save the following code...any idea what I've got wrong? 

Error: Compile Error: Illegal assignment from List<Proposal__c> to Id at line 13 column 3


public with sharing class AnotherController
{
 private ApexPages.StandardController stdCtrl;
  
 public AnotherController(ApexPages.StandardController std)
 {
  stdCtrl=std;
 }
  
 public void PopulateProject()
 {
  Project__c proj=(Project__c) stdCtrl.getRecord();
  proj.Proposal__c=[select Scope_of_Work__c from Proposal__c where Id=:proj.Proposal__c];
  proj.Scope_of_Work__c=proj.Proposal__c.Scope_of_Work__c;
 }
}