• Akanksha sharma 15
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 4
    Replies
My scenario is when i filled details on page 1 and will click on next button i will get page2 and on that page i have previous button when i click previous button already filled on page 1 details should be display i am not getting any idea that when i click on previous button how can i get  filled details there. anyone can help me out in this.Thanks in advance
How to create a post method using Json using wrapper class  in salesforce 
there is look up relationship between opportunity and case i need to find soql qery to find all related case for opportunity here is my query please anyone help where i am wrong

 
<apex:page standardController="Opportunity" extensions="stucasecontroller1">
   <apex:form >
   <apex:pageBlock title="relatedlist details">
   
   <apex:pageblockSection title="case realted list ">
   <apex:pageBlocktable value="{!cas}" var="c" >
   
   <apex:column value="{!c.status}"/>
   <apex:column value="{!c.origin}"/>
   </apex:pageblocktable>
   </apex:pageblockSection>
   
   </apex:pageBlock>
   
  </apex:form>
</apex:page>


 public class stucasecontroller1 {

public string oppID{get;set;}
public List<case> caslist{get;set;}


    public stucasecontroller1 (){
       cas=[select Id,status,origin,opportunity__r.Name,opportunity__c  from case where opportunity__c=:oppID];

    }


   


    

}
When i click on clone and study button that is present on related list of opportunity a new page should be open where i can see all related records of object study  and case (with checkbox)and when i will  click on clone button  that selected records should be clone on related list.But  what happened with my code all records being clone on related list i need to clone only selected records.
Mu concern is i am not able to use  selected checkbox in a query to update selected records. can anyone help me

<
<apex:page standardController="Opportunity" extensions="stucasecontroller">
   <apex:form >
   <apex:pageBlock title="relatedlist details">
   
   <apex:pageblockSection title="case realted list ">
   <apex:pageBlocktable value="{!cas}" var="c" >
   <apex:column headervalue="Action">
<apex:inputcheckbox />
</apex:column>
   <apex:column value="{!c.status}"/>
   <apex:column value="{!c.origin}"/>
   </apex:pageblocktable>
   </apex:pageblockSection>
   
   <apex:pageBlockSection title="Study relatedlist">
   <apex:pageBlocktable value="{!stu}" var="s" >
   <apex:column headervalue="Action">
<apex:inputcheckbox />
</apex:column>
   <apex:column value="{!s.Name}"/>
   <apex:column value="{!s.Rollno__c}"/>
   </apex:pageblocktable>
   </apex:pageblockSection>   
   </apex:pageBlock>
   
   <apex:commandButton value="clone on relatedlist" action="{!relatedlistclone}"/>
  </apex:form>
</apex:page>


public class stucasecontroller {

public List<case> cas{get;set;}
public List<study__c> stu{get;set;}

    public stucasecontroller(ApexPages.StandardController controller) {
    String oppID='0060K00000RZfqbQAD';
    cas=[select Id,status,origin,opportunity__r.Name,opportunity__c  from case where opportunity__c=:oppID];
   string stuid='0060K00000RZfqbQAD';
  stu=[select Name,Rollno__c,opportunity__r.Name from study__c where opportunity__c=:stuid];
   

    }


    public PageReference relatedlistclone() {
       List<case> cas=[select Id,status,origin,opportunity__r.Name,opportunity__c  from case where opportunity__c='0060K00000RZfqbQAD' and Action='True'];
         List<study__c> stu=[select Name,Rollno__c,opportunity__r.Name from study__c where opportunity__c='0060K00000RZfqbQAD'];
         List<case> cloneList=cas.deepclone();
         List<study__c> stulidt=stu.deepclone();
        insert cloneList;
        insert stulidt;
        pagereference pr = new pagereference('https://c.ap6.visual.force.com/apex/relatedopp?id=0060K00000RZfqb');  
        return pr;
        
    }




    

}

 
select Id,status,Priority,opportunity__r.Name,opportunity__c  from case where id=:Opportunity__c
select Id,status,Priority,opportunity__r.Name,opportunity__c  from case where id=:Opportunity__c

 
 

my scenario is when i will click on new opportunity button a new opportunity page should open where i fill the details and click on save then it will redirect to the list page of opportunity where records save with edit and delete link when click on edit link edit page should open i have done till that but when i click on delete link it should deleted i am not abe to do for delete when i am deleting record a new bank page open
 

    <apex:page StandardController="Opportunity" Extensions="secondpage" >
        <apex:form >
        <apex:pageBlock >
    
        <apex:pageBlockButtons location="Top" >
         <apex:commandButton value="Save" action="{!saverec}"/> <br/><br/>
         
         <apex:commandLink action="{!editOpp}" value="Edit"/>
      <apex:param value="{!opp.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
      <apex:commandLink action="{!deleteOpp}" value="Delete" />
     <apex:param value="{!opp.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        </apex:pageBlockButtons>
        <apex:pageblockSection >
           <apex:inputfield value="{!opp.Name}" />
            <apex:inputfield value="{!opp.StageName}"/>
             <apex:inputfield value="{!opp.AccountId}"/>
             <apex:inputfield value="{!opp.Amount}"/>
            <apex:inputfield value="{!opp.closeDate}"/>
       </apex:pageblockSection>
                </apex:pageBlock>   
        </apex:form>
    </apex:page>

----

    public class secondpage {
    
       
        Public Opportunity opp{get;set;}
        Public String op1;
         public id accid{set;get;}
       public String selectedAccId {get;set;}
          public String selectedoppId{get;set;}
        public secondpage(ApexPages.StandardController stdController) {
            
       
            Opp= (Opportunity)stdController.getRecord();
               
            
        }
       
       
        public PageReference saverec() {
           
            insert opp;
           
            pagereference pr = new pagereference('https://c.ap6.visual.force.com/apex/Opp2');
           
            return pr;
        }
    
    
        public Pagereference editOpp()
     {
         
           PageReference ref = new PageReference('/'+selectedAccId+'/e?retURL=%2F'+selectedAccId);
            return ref;
     }
     
     public Pagereference deleteOpp()
     {
            return null;
    
            }
     }

----

    <apex:page Controller="mycontroller1">
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockSection >
    <apex:pageBlockTable value="{!Opportunitylst}" var="op">
    <apex:column value="{!op.Name}"/>
    <apex:column value="{!op.StageName}"/>
    <apex:column value="{!op.Amount}" />
    <apex:column value="{!op.accountId}"/>
    <apex:column value="{!op.CloseDate}"/>
    <apex:column headerValue="Action" >
      <apex:commandLink value="Edit /" action="{!editOpp}">
        <apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        </apex:commandLink>
        
        <apex:commandLink action="{!deleteOpp}" value="Delete"/>
     <apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        
        
    </apex:column>                        
    </apex:pageBlockTable>
    </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
    </apex:page>

----
                        
    public class mycontroller1 {
    
        public List<Opportunity> Opp{get;set;}
        Public List<Opportunity> Opportunitylst{get;set;}
        public String selectedAccId {get;set;}
    
    
      public PageReference deleteOpp() {
              
opportunitylst=[select Name,AccountId,Amount,CloseDate,StageName from Opportunity where id=:selectedAccId];      
delete  opportunitylst;     
  return null;
              
              }
    
                 
                 
                 
        public mycontroller1(){
            Opportunitylst=[select Name,AccountId,Amount,CloseDate,StageName from Opportunity order by createdDate DESC limit 10 ];
         }
        public Pagereference editOpp()
     {
         p
           PageReference ref = new PageReference('/'+selectedAccId+'/e?retURL=%2F'+selectedAccId);
            return ref;
     }
    }

 
there is look up relationship between opportunity and case i need to find soql qery to find all related case for opportunity here is my query please anyone help where i am wrong

 
<apex:page standardController="Opportunity" extensions="stucasecontroller1">
   <apex:form >
   <apex:pageBlock title="relatedlist details">
   
   <apex:pageblockSection title="case realted list ">
   <apex:pageBlocktable value="{!cas}" var="c" >
   
   <apex:column value="{!c.status}"/>
   <apex:column value="{!c.origin}"/>
   </apex:pageblocktable>
   </apex:pageblockSection>
   
   </apex:pageBlock>
   
  </apex:form>
</apex:page>


 public class stucasecontroller1 {

public string oppID{get;set;}
public List<case> caslist{get;set;}


    public stucasecontroller1 (){
       cas=[select Id,status,origin,opportunity__r.Name,opportunity__c  from case where opportunity__c=:oppID];

    }


   


    

}
 

my scenario is when i will click on new opportunity button a new opportunity page should open where i fill the details and click on save then it will redirect to the list page of opportunity where records save with edit and delete link when click on edit link edit page should open i have done till that but when i click on delete link it should deleted i am not abe to do for delete when i am deleting record a new bank page open
 

    <apex:page StandardController="Opportunity" Extensions="secondpage" >
        <apex:form >
        <apex:pageBlock >
    
        <apex:pageBlockButtons location="Top" >
         <apex:commandButton value="Save" action="{!saverec}"/> <br/><br/>
         
         <apex:commandLink action="{!editOpp}" value="Edit"/>
      <apex:param value="{!opp.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
      <apex:commandLink action="{!deleteOpp}" value="Delete" />
     <apex:param value="{!opp.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        </apex:pageBlockButtons>
        <apex:pageblockSection >
           <apex:inputfield value="{!opp.Name}" />
            <apex:inputfield value="{!opp.StageName}"/>
             <apex:inputfield value="{!opp.AccountId}"/>
             <apex:inputfield value="{!opp.Amount}"/>
            <apex:inputfield value="{!opp.closeDate}"/>
       </apex:pageblockSection>
                </apex:pageBlock>   
        </apex:form>
    </apex:page>

----

    public class secondpage {
    
       
        Public Opportunity opp{get;set;}
        Public String op1;
         public id accid{set;get;}
       public String selectedAccId {get;set;}
          public String selectedoppId{get;set;}
        public secondpage(ApexPages.StandardController stdController) {
            
       
            Opp= (Opportunity)stdController.getRecord();
               
            
        }
       
       
        public PageReference saverec() {
           
            insert opp;
           
            pagereference pr = new pagereference('https://c.ap6.visual.force.com/apex/Opp2');
           
            return pr;
        }
    
    
        public Pagereference editOpp()
     {
         
           PageReference ref = new PageReference('/'+selectedAccId+'/e?retURL=%2F'+selectedAccId);
            return ref;
     }
     
     public Pagereference deleteOpp()
     {
            return null;
    
            }
     }

----

    <apex:page Controller="mycontroller1">
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockSection >
    <apex:pageBlockTable value="{!Opportunitylst}" var="op">
    <apex:column value="{!op.Name}"/>
    <apex:column value="{!op.StageName}"/>
    <apex:column value="{!op.Amount}" />
    <apex:column value="{!op.accountId}"/>
    <apex:column value="{!op.CloseDate}"/>
    <apex:column headerValue="Action" >
      <apex:commandLink value="Edit /" action="{!editOpp}">
        <apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        </apex:commandLink>
        
        <apex:commandLink action="{!deleteOpp}" value="Delete"/>
     <apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        
        
    </apex:column>                        
    </apex:pageBlockTable>
    </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
    </apex:page>

----
                        
    public class mycontroller1 {
    
        public List<Opportunity> Opp{get;set;}
        Public List<Opportunity> Opportunitylst{get;set;}
        public String selectedAccId {get;set;}
    
    
      public PageReference deleteOpp() {
              
opportunitylst=[select Name,AccountId,Amount,CloseDate,StageName from Opportunity where id=:selectedAccId];      
delete  opportunitylst;     
  return null;
              
              }
    
                 
                 
                 
        public mycontroller1(){
            Opportunitylst=[select Name,AccountId,Amount,CloseDate,StageName from Opportunity order by createdDate DESC limit 10 ];
         }
        public Pagereference editOpp()
     {
         p
           PageReference ref = new PageReference('/'+selectedAccId+'/e?retURL=%2F'+selectedAccId);
            return ref;
     }
    }

 
Hi All,

I want to display number of contacts associated with an account using triggers.

for this I had created a lookup field like noofcontacts__c in account  object. and Wrote code as

trigger numberofcontacts on contact(after insert, after update, after delete) {
    Map<Id, List<Contact>> AcctContactList = new Map<Id, List<Contact>>();
    Set<Id> AcctIds = new Set<Id>();   
    List<schema.Account> AcctList = new List<schema.Account>();
    List<schema.Contact> ConList = new List<schema.Contact>();
   
    if(trigger.isInsert || trigger.isUPdate) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId)){
                AcctIds.add(Con.AccountId); 
            }  
        } 
    }
   
    if(trigger.isDelete) {
        for(Contact Con : trigger.Old) {
            AcctIds.add(Con.AccountId);    
        } 
    }          
   
    if(AcctIds.size() > 0){
        ConList = [SELECT Id, AccountId FROM Contact WHERE AccountId IN : AcctIds];
       
        for(Contact Con : ConList) {
            if(!AcctContactList.containsKey(Con.AccountId)){
                AcctContactList.put(Con.AccountId, new List<Contact>());
            }
            AcctContactList.get(Con.AccountId).add(Con);     
        }                          
      
           
        AcctList = [SELECT noofContacts__c FROM Account WHERE Id IN : AcctIds];
        for(Account Acc : AcctList) {
            List<schema.Contact> ContList = new List<schema.Contact>();
            ContList = AcctContactList.get(Acc.Id);
            Acc.Number_of_Contacts__c = ContList.size();
        }   
       
      
        update AcctList;   
    }

}
 I am   getting an error as "Variable doesnot exist:id".

Kindly support and suggest.

Thanks