• Abhishek Purohit
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 6
    Replies
trigger ShippingBillingAddress on Account (before insert,before update,after insert,after update) {
 if(Trigger.isBefore)
    {
    for(Account accountList:Trigger.New)
     {
     if(Trigger.isInsert)
     
      {
     
     accountList.ShippingStreet=accountList.BillingStreet;
     accountList.ShippingCountry=accountList.BillingCountry;
     accountList.ShippingCity=accountList.BillingCity;
     accountList.ShippingState=accountList.BillingState;
     }
    
      if(Trigger.isUpdate)
     { 
      accountList.ShippingStreet=accountList.BillingStreet;
     accountList.ShippingCountry=accountList.BillingCountry;
     accountList.ShippingCity=accountList.BillingCity;
     accountList.ShippingState=accountList.BillingState;
      }
      
      
     }
    
      
       
       
       
    } 

 if(Trigger.IsAfter)
   {
   List<Contact> contactCreate=new List<Contact>();
   for(Account accountList2:Trigger.New)
    {
    if(Trigger.IsInsert)
      {
    Contact contactrecordCreate=new Contact();
      contactrecordCreate.accountId=accountList2.Id;
      contactrecordCreate.LastName=accountList2.Name;
      contactrecordCreate.Phone=accountList2.Phone;
      
      contactCreate.add(contactrecordCreate);
     }
     
  insert contactCreate;
  
  }
  }
  

    

}

 
trigger OpportunityCreator on Account (after insert) {
 
 if(Trigger.isInsert)
 {
   List<Opportunity> oCreate=new List<Opportunity>();
   List<Activity_Plan__c> actplanList=new List<Activity_Plan__c>();
   for(Account acc :Trigger.New)
   {
    
    Opportunity op=new Opportunity();
    Activity_Plan__c apobj =new  Activity_Plan__c();
    
   //op.accountId=acc.Id; 
    op.Name=acc.Name;
    op.CloseDate=Date.today();
    op.StageName='Prospecting';
    apobj.name=acc.Name;
    apobj.Object__c=acc.Name;
   
   oCreate.add(op);  
   actplanList.add(apobj);
 } 
 
 insert oCreate;
 insert actplanList;
  
 }
 

}

 
this is vf3 page
<apex:page controller="OppControl">
 <apex:form >
  <apex:pageBlock title="Search The Opportunities">
   Name: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<apex:inputText value="{!key}"/>
     <apex:commandButton value="Go" action="{!search}"/>
        <apex:commandButton value="Add Opportunity " action="{!add}"/>
       <apex:pageBlockTable value="{!myop}" var="my">
       <apex:column ><apex:outputLink value="/{!my.id}">"{!my.Name}"</apex:outputLink></apex:column>
        
         <apex:column value="{!my.StageName}"/>
         <apex:column value="{!my.Amount}"/>
         <apex:column value="{!my.CloseDate}"/>     
      </apex:pageBlockTable>
  </apex:pageBlock>  
 </apex:form>
</apex:page>





This one redirects from the add opportunity button

<apex:page controller="OppControl">
  <apex:form >
  
  <apex:pageBlock title="The New Opportunity">
    <apex:pageBlockSection title="Section One"> 
     <apex:outputText value="Enter The Name"></apex:outputText>
     <apex:inputText />
    </apex:pageBlockSection>
    
    
  <apex:pageBlockSection title="Section Two"> 
     <apex:outputText value="Enter The Amount"></apex:outputText>
     <apex:inputText />
    </apex:pageBlockSection>
  
  <apex:pageBlockSection title="Section Three"> 
     <apex:outputText value="Enter The Stage Name"></apex:outputText>
     <apex:inputText />
    </apex:pageBlockSection>
  
  <apex:pageBlockSection title="Section Four"> 
     <apex:outputText value="Enter The Closed Date"></apex:outputText>
    <apex:inputText />
    
    <apex:commandButton value="Save it" action="{!save}"/>
    </apex:pageBlockSection>
  </apex:pageblock>
  </apex:form>
</apex:page>




This is my Custom Controller

public class OppControl{

    

    String key;
    List<Opportunity> myop;
    String SearchQuery{get;set;}
    public String getkey(){
    return key;
    }
  public OppControl(){
  myop=[Select Name,Amount,StageName,CloseDate From Opportunity];
  }
    public List<Opportunity> getmyop(){
    return myop;
    }

   public void setkey(String ip){
     key=ip;
   }

   public PageReference search(){
    SearchQuery='Select Name,StageName,Amount,CloseDate From Opportunity where Name like '+'\''+key+'%'+'\''; 
    myop=database.query(SearchQuery);
   return null;
}   
   public PageReference add(){
   return Page.vf4;
   
   
  
  } 
   public PageReference save(){
   return Page.vf3;
   }
   
}


Now I want to add the record like for real in the database using this controller and also after it has been saved on that vf4 page should be able to show the name stagename closedate amount on the vf3 page

 

Hello,

 

I am still very new to APEX.  I am trying to develop a simple visualforce page that lists all the accounts the active user owns.  Ideally, the user should be able to edit and save the records.  When the user clicks save, the record in the database should update.  Currently, the edit and save buttons do not work but I can make changes when double clicking but they do not save.  Any help is greatly appreciated.

 

My code so far:

 

*********************Visualforce page************************

 

<apex:page controller="MyController" >
     
      <apex:form >
     
        <apex:pageBlock title="My Accounts">
       
           
                <apex:pageblocktable value="{!myaccounts}" var="acct">
                    <apex:column value="{! acct.name}"/>
                    <apex:column value="{! acct.Preferred_Mode_S__c}"/>
                    <apex:column value="{! acct.type}"/>
                     <apex:inlineEditSupport event="ondblclick"/>
                  
                </apex:pageblocktable>
                <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandbutton value="Edit" action="{!edit}"/>
        </apex:pageblock>
  </apex:form>
</apex:page>

 

 

*****************************Controller*****************************

 

public class MyController {

         public List<Account> getMyAccounts(){        

List<Account> a = new List<Account>();        

a = [select Id,name,type,preferred_mode_s__c,macro_industry__c,micro_industry__c from Account WHERE (owner.id =: userinfo.getuserid())];            

return a;           

}   

 

public PageReference edit() {        

return null;    

}

    public PageReference save() {        

return null;    

}

}