• cassy
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies

Hey everyone,

 

I'm a beginner in writing Apex Codes and I have a question about Trigger. Is it possible to set an lookup Field of an standard Object with a Trigger??

I have an Event Field and an Year Field for this Event in my Opportunities now I want to select the Campaign, which has the same Event and the same Year and put it into an lookup field. Is it possible to do this with a Trigger??

 

 

I will be very thankful if anyone of you can help me.

 

Thanks in advance

  • May 05, 2012
  • Like
  • 0

Hallo everyone,

 

I want to put Accountinformation in an pageBlockTable also the Owner Name of the Account , but Accounts have only a lookup Field with the OwnerId. How can i get the Name of the Owner without writing a trigger??

  • April 23, 2012
  • Like
  • 0

Hallo everyone,

 

I want to write a switch-case block the convention in Java  is:

 

switch( variable)

{

case value:

statement;

break;

case value:

statement;

break;

default

statement;

break;

}

 

or is it different in Apex because I get an exception.


Save error: unexpected token: '{'    after switch(variable).

 

  • April 23, 2012
  • Like
  • 0

Hallo everyone,

 

my name ist Cassandra an I'm a beginner in developing VisualPages, now I want to create a Visualforce Page, that can search for Accounts, Contacts And Opportunities given in a Customer Object called Hannover_ Potentials. The AccountName, -street, -City and ZipCode is given in the CustomerObject as  Formalfields and also the firstName And LastName Of the Contacts are given and the Name of the Opportunity.

I have written a search Method in me extensionController SearchController, where I selected all Hannover_Potential Objects with the same accountname as my inputName and accountcity is like my inputcity etc...Then I select in Account all Accounts, who have the same name as the Accountname of my hannover_Potential Object and write them into a list of Accounts.

I do the same for the Contacts and for the opportunities.

Then I have a list of Accounts, Contacts and Opportunities and I want to put them in PageblockTables.

But I think my search-function is going wrong, because I get this Error Massage, when I click on my SearchButton in my Visualforce Page.

 

System.NullPointerException: Attempt to de-reference a null object 

 

I know that my Visualfocepage code is correct because I have tested it with an other Controller and everything was fine. So the mistake must be in my Searchcontrollerclass.

 


Here is the Code Of my ControllerClass

public with sharing class SearchController {

     //AusgabeListe 
     public Account [] acc{get; set;}
     public Opportunity [] opp{get; set;}
     public Contact [] con1{get; set;}
     public Contact [] con2{get;set;}
     
 // InputText Argumente
     public String firstName1{get; set;}
     public String lastName1{get;set;}
     public String street1{get; set;}
     public String city1{get; set;}
     public String plz1{get; set;}
 //Constructor
    public SearchController(ApexPages.StandardSetController controller) {
        firstName1='';
        lastName1='';
        city1='';
        street1='';
        plz1='';
        
    }
 // Action for Search Button
    public PageReference search1() {
        
       this.searchH();
                return null;
    }
public void searchH() {
         Account tempacc;
         Contact tempcon;
         Opportunity tempopp;
         Integer a=1;
         
         
         
         // Search for Accounts
            for(Hannover_Potentials__c hp:[SELECT Account_Name__c,Account_ZIP_CODE__c,Account_City__c,Account_Street__c FROM Hannover_Potentials__c WHERE Account_Name__c like:('%'+firstName1+'%') and ( Account_Street__c like:('%'+street1+'%') and Account_City__c like:('%'+city1+'%') and Account_ZIP_CODE__c like:('%'+plz1+'%'))])
           {
                tempacc=[SELECT Id, OwnerId, Name, BillingStreet, BillingCity, BillingPostalCode FROM Account WHERE Name like: ('%'+hp.Account_Name__c+'%') and BillingCity like: ('%'+hp.Account_City__c+'%') and BillingStreet like: ('%'+hp.Account_Street__c+'%') and BillingPostalCode like: ('%'+hp.Account_ZIP_CODE__c +'%')];
                 System.debug('aaaaaaaaaaaaaaaaaaa'+tempacc.Name);
                acc[a]=tempacc;
                a=a+1;
            }
            
            
            a=0;
            
            //Search for Contact 1
           for(Hannover_Potentials__c hp:[SELECT  General_Contact_Person_First_Name__c, General_Contact_Person_Last_Name__c FROM Hannover_Potentials__c WHERE General_Contact_Person_First_Name__c like:('%'+firstName1+'%') and General_Contact_Person_Last_Name__c like:('%'+lastName1+'%')])
           {
                tempcon= [SELECT Id,Name, OwnerId, Email FROM Contact WHERE FirstName like: ('%'+hp.General_Contact_Person_First_Name__c+'%') and LastName like: ('%'+hp.General_Contact_Person_Last_Name__c+'%')];
                con2[a]=tempcon;
                a=a+1;
            }
            
            a=0;
            
            
           // Search for Contact 2
           for(Hannover_Potentials__c hp:[SELECT Main_Contact_Last_Name__c, Main_Contact_First_Name__c FROM Hannover_Potentials__c WHERE Main_Contact_First_Name__c like:('%'+firstName1+'%') and Main_Contact_Last_Name__c like:('%'+lastName1+'%')])
           {
                tempcon= [SELECT Id, Name, OwnerId, Email FROM Contact WHERE FirstName like: ('%'+hp.Main_Contact_First_Name__c+'%') and LastName like: ('%'+hp.Main_Contact_Last_Name__c+'%')];
                con1[a]=tempcon;
                a=a+1;
            }
            
            a=0;
            //suche nach Opportunities
           for(Hannover_Potentials__c hp:[SELECT Opportunity_Name__c FROM Hannover_Potentials__c WHERE Opportunity_Name__c like:('%'+firstName1+'%') or Opportunity_Name__c like:('%'+lastName1+'%')])
           {
                tempopp= [SELECT Id, Name FROM Opportunity WHERE Name like: ('%'+hp.Opportunity_Name__c+'%')];
                opp[a]=tempopp;
                a=a+1;
            }
            a=0;

return;
}
}


  And my debugcall informed me the in the problem is here in my for loop:

 tempcon= [SELECT Id,Name, OwnerId, Email FROM Contact WHERE FirstName like: ('%'+hp.General_Contact_Person_First_Name__c+'%') and LastName like: ('%'+hp.General_Contact_Person_Last_Name__c+'%')];
                con2[a]=tempcon;
                a=a+1;

I will be very happy for every advices, you can give me.

 

Thanks in advance

 

Cassandra

 

 

  • April 20, 2012
  • Like
  • 0

Hallo everyone,

 

I want to write a switch-case block the convention in Java  is:

 

switch( variable)

{

case value:

statement;

break;

case value:

statement;

break;

default

statement;

break;

}

 

or is it different in Apex because I get an exception.


Save error: unexpected token: '{'    after switch(variable).

 

  • April 23, 2012
  • Like
  • 0

Hallo everyone,

 

my name ist Cassandra an I'm a beginner in developing VisualPages, now I want to create a Visualforce Page, that can search for Accounts, Contacts And Opportunities given in a Customer Object called Hannover_ Potentials. The AccountName, -street, -City and ZipCode is given in the CustomerObject as  Formalfields and also the firstName And LastName Of the Contacts are given and the Name of the Opportunity.

I have written a search Method in me extensionController SearchController, where I selected all Hannover_Potential Objects with the same accountname as my inputName and accountcity is like my inputcity etc...Then I select in Account all Accounts, who have the same name as the Accountname of my hannover_Potential Object and write them into a list of Accounts.

I do the same for the Contacts and for the opportunities.

Then I have a list of Accounts, Contacts and Opportunities and I want to put them in PageblockTables.

But I think my search-function is going wrong, because I get this Error Massage, when I click on my SearchButton in my Visualforce Page.

 

System.NullPointerException: Attempt to de-reference a null object 

 

I know that my Visualfocepage code is correct because I have tested it with an other Controller and everything was fine. So the mistake must be in my Searchcontrollerclass.

 


Here is the Code Of my ControllerClass

public with sharing class SearchController {

     //AusgabeListe 
     public Account [] acc{get; set;}
     public Opportunity [] opp{get; set;}
     public Contact [] con1{get; set;}
     public Contact [] con2{get;set;}
     
 // InputText Argumente
     public String firstName1{get; set;}
     public String lastName1{get;set;}
     public String street1{get; set;}
     public String city1{get; set;}
     public String plz1{get; set;}
 //Constructor
    public SearchController(ApexPages.StandardSetController controller) {
        firstName1='';
        lastName1='';
        city1='';
        street1='';
        plz1='';
        
    }
 // Action for Search Button
    public PageReference search1() {
        
       this.searchH();
                return null;
    }
public void searchH() {
         Account tempacc;
         Contact tempcon;
         Opportunity tempopp;
         Integer a=1;
         
         
         
         // Search for Accounts
            for(Hannover_Potentials__c hp:[SELECT Account_Name__c,Account_ZIP_CODE__c,Account_City__c,Account_Street__c FROM Hannover_Potentials__c WHERE Account_Name__c like:('%'+firstName1+'%') and ( Account_Street__c like:('%'+street1+'%') and Account_City__c like:('%'+city1+'%') and Account_ZIP_CODE__c like:('%'+plz1+'%'))])
           {
                tempacc=[SELECT Id, OwnerId, Name, BillingStreet, BillingCity, BillingPostalCode FROM Account WHERE Name like: ('%'+hp.Account_Name__c+'%') and BillingCity like: ('%'+hp.Account_City__c+'%') and BillingStreet like: ('%'+hp.Account_Street__c+'%') and BillingPostalCode like: ('%'+hp.Account_ZIP_CODE__c +'%')];
                 System.debug('aaaaaaaaaaaaaaaaaaa'+tempacc.Name);
                acc[a]=tempacc;
                a=a+1;
            }
            
            
            a=0;
            
            //Search for Contact 1
           for(Hannover_Potentials__c hp:[SELECT  General_Contact_Person_First_Name__c, General_Contact_Person_Last_Name__c FROM Hannover_Potentials__c WHERE General_Contact_Person_First_Name__c like:('%'+firstName1+'%') and General_Contact_Person_Last_Name__c like:('%'+lastName1+'%')])
           {
                tempcon= [SELECT Id,Name, OwnerId, Email FROM Contact WHERE FirstName like: ('%'+hp.General_Contact_Person_First_Name__c+'%') and LastName like: ('%'+hp.General_Contact_Person_Last_Name__c+'%')];
                con2[a]=tempcon;
                a=a+1;
            }
            
            a=0;
            
            
           // Search for Contact 2
           for(Hannover_Potentials__c hp:[SELECT Main_Contact_Last_Name__c, Main_Contact_First_Name__c FROM Hannover_Potentials__c WHERE Main_Contact_First_Name__c like:('%'+firstName1+'%') and Main_Contact_Last_Name__c like:('%'+lastName1+'%')])
           {
                tempcon= [SELECT Id, Name, OwnerId, Email FROM Contact WHERE FirstName like: ('%'+hp.Main_Contact_First_Name__c+'%') and LastName like: ('%'+hp.Main_Contact_Last_Name__c+'%')];
                con1[a]=tempcon;
                a=a+1;
            }
            
            a=0;
            //suche nach Opportunities
           for(Hannover_Potentials__c hp:[SELECT Opportunity_Name__c FROM Hannover_Potentials__c WHERE Opportunity_Name__c like:('%'+firstName1+'%') or Opportunity_Name__c like:('%'+lastName1+'%')])
           {
                tempopp= [SELECT Id, Name FROM Opportunity WHERE Name like: ('%'+hp.Opportunity_Name__c+'%')];
                opp[a]=tempopp;
                a=a+1;
            }
            a=0;

return;
}
}


  And my debugcall informed me the in the problem is here in my for loop:

 tempcon= [SELECT Id,Name, OwnerId, Email FROM Contact WHERE FirstName like: ('%'+hp.General_Contact_Person_First_Name__c+'%') and LastName like: ('%'+hp.General_Contact_Person_Last_Name__c+'%')];
                con2[a]=tempcon;
                a=a+1;

I will be very happy for every advices, you can give me.

 

Thanks in advance

 

Cassandra

 

 

  • April 20, 2012
  • Like
  • 0