• sravanthi_84
  • NEWBIE
  • 75 Points
  • Member since 2010

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

How to i populate custom picklist in triggers

Hi,

 

I am trying to create an apex trigger on Opportunity to update a checkbox when the Opportunity stage changes to a certain value. The reason why I need a trigger is because that trigger will allow another workflow to fire when the checkbox is updated.

 

I created the code but it seems to be looking at all opportunities and I do not know how to have the trigger look at this current opportunity only. Can anyone please tel me what is wrong with this code.

 

 

trigger OpptyFollowup on Opportunity (after insert, after update) {


Opportunity oppty = trigger.new[0];


if( 'Followup' .equals(oppty.StageName)){

for(Opportunity o:[Select Alarm__c from Opportunity]){

oppty = o;
oppty.Alarm__c = true;

update oppty;

}

}

}

I am sure that I have an Account record that the name is 'Acme', but the follow statements cannot fetch the record. 

The records.size() is 0. What is wrong?

    public static void testSOSL () {
        List<List<sObject>> results = [FIND 'Acme' IN NAME FIELDS RETURNING Account (id, name), Contact, Lead];
        
        sObject[] records = ((List<sObject>)results[0]);

        System.debug('\n\n\n' + records.size() + '\n\n\n');   
    }

 

Environment: Sandbox full

  • September 24, 2010
  • Like
  • 0

Hi All,

          I have a small problem with my controller. I am trying to get values from a custom object  and trying to update the values. But it is not working fine. I have paste the visualforce code and the controller below:

 

 

<apex:page standardcontroller="Case" sidebar="false" showHeader="false" extensions="SubmitCaseController">
             
                           
       <apex:outputPanel styleClass="box1" style="border-style:none;border-widht:0px;background-color: #FFFFFF;margin-top:35px" >        
 
         <apex:outputPanel styleClass="box1" style="border:none">
    <apex:dataTable columns="2" id="firstbox1" value="{!List}" var="p" rendered="{!(List!=null)}">
        <apex:column styleClass="c1">
            <apex:outputtext value="Profile Name"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Name}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Operating System"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.operating_system__c}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Application Development Language"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Application_Development_Language__c}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Database"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Database__c}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Web Server"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Web_Server__c}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Servlet Engine"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Servlet_Engine__c}" style="width:250px"/>
        </apex:column>
         <apex:column styleClass="bbox1">
                                                     <apex:column styleClass="bbox1">
              
<apex:commandButton value="Update" action="{!Save}" />
               </apex:column>
    </apex:dataTable>               
</apex:outputPanel>    
                     </apex:outputPanel>
        </apex:form>
   </apex:outputPanel>
</apex:page>

 

My controller is as follows:

 

public abstract class SubmitCaseController {

   
    public SubmitCaseController(ApexPages.StandardController controller) {
           }
    
   public List<Customer_Profile__c> cList{get;set;}
                 
   public PageReference Save(){
             update cList;
             return null;
   }
  
    
      public List<Customer_Profile__c> getList(){     
        cList = [select Id,Name,Application_Development_Language__c,Database__c,operating_system__c,Servlet_Engine__c,Web_Server__c from Customer_Profile__c where Account__r.Name =:accName];
              return cList;
    }        
    
     }

 

 

Can anyone please help me with this issue. Thanks in advance.

I have uploaded an attachment to a custom object and need to retrieve the attachment to a visualforce page and should be able to update it with new attachment. The  following code inserts an attachment and the parentId for this attachment is recId1.

 

 

 public PageReference UploadFile1()
    {          
        if(fileBody1 != null && fileName1 != null)
        {
          Attachment myAttachment1  = new Attachment();
          myAttachment1.Body = fileBody1;
          myAttachment1.Name = fileName1;
          myAttachment1.ParentId =recId1;
          insert myAttachment1;
        }
        return Page.webform;
    }  
 

Can anyone tell me how to retrieve an attachment to a visualforce page and update it .

 

Thanks in advance.

How to i populate custom picklist in triggers

hi,

 

I tried to create master-detail relationship on standard objects. However, there is no option for it.

why can't we make standard object on detail side of any custom object ?

 

Thanks,

dayanand

  • September 26, 2010
  • Like
  • 0

Hi,

 

I am trying to create an apex trigger on Opportunity to update a checkbox when the Opportunity stage changes to a certain value. The reason why I need a trigger is because that trigger will allow another workflow to fire when the checkbox is updated.

 

I created the code but it seems to be looking at all opportunities and I do not know how to have the trigger look at this current opportunity only. Can anyone please tel me what is wrong with this code.

 

 

trigger OpptyFollowup on Opportunity (after insert, after update) {


Opportunity oppty = trigger.new[0];


if( 'Followup' .equals(oppty.StageName)){

for(Opportunity o:[Select Alarm__c from Opportunity]){

oppty = o;
oppty.Alarm__c = true;

update oppty;

}

}

}

I am sure that I have an Account record that the name is 'Acme', but the follow statements cannot fetch the record. 

The records.size() is 0. What is wrong?

    public static void testSOSL () {
        List<List<sObject>> results = [FIND 'Acme' IN NAME FIELDS RETURNING Account (id, name), Contact, Lead];
        
        sObject[] records = ((List<sObject>)results[0]);

        System.debug('\n\n\n' + records.size() + '\n\n\n');   
    }

 

Environment: Sandbox full

  • September 24, 2010
  • Like
  • 0

I've got a trigger I wrote and put in our sandbox, it works great and production has all the same fields.  So now I have to build the class to test it. I thought I had it and it errors out instead.

 

The trigger is as follows and does work...

 

 

trigger OwnerLinkUpdate on Opportunity (before insert, before update ) {
 for (Opportunity a :Trigger.NEW) {
    a.Owner_Link__c = a.OwnerId;
    a.TM_Descr__c = a.Description.substring(1, 100); 
    }
}

 

trigger OwnerLinkUpdate on Opportunity (before insert, before update ) {

for (Opportunity a :Trigger.NEW) {

a.Owner_Link__c = a.OwnerId;

a.TM_Descr__c = a.Description.substring(1, 100);

}

}

 

And below is my class I currently have but know it is wrong.

 

@isTest

private class TestOwner_link {

 

    public static testMethod void OwnerLinkTest() {

     Opportunity o = [Select o.Id, o.Description FROM Opportunity o WHERE o.ID = '006Q0000005MIEK'];

o.Description = 'P123456789 - Appt Secured 9/21/2010 16:00 - Test Description to see if this will update correctly.';

        update o;

    

       Opportunity opp = new Opportunity(name = 'IS TEST 2' , StageName = 'Prospect',

        AccountId = '001Q000000EmsJs', OwnerId = '00580000001khcs',

        CloseDate = date.newinstance(2010, 10, 21), Product_Service_Type__c = 'Alarm',

        Product_Service_Detail__c = 'Burglar Alarm System', Type = 'NEW',

        Level__c = 'Recommended (We seek out the account to give them a proposal.)',

        LeadSource = 'Sales Rep Generated', Description = 'Text', External_ID__c = 'P123456789');

       insert opp;

 

    }

}

 

 

Any help would be appreciated, I have been reading posts and can't seem to find anything that seems to make the class work and the trigger cover 100%.

 

 

 

  • September 24, 2010
  • Like
  • 0

Hi All,

          I have a small problem with my controller. I am trying to get values from a custom object  and trying to update the values. But it is not working fine. I have paste the visualforce code and the controller below:

 

 

<apex:page standardcontroller="Case" sidebar="false" showHeader="false" extensions="SubmitCaseController">
             
                           
       <apex:outputPanel styleClass="box1" style="border-style:none;border-widht:0px;background-color: #FFFFFF;margin-top:35px" >        
 
         <apex:outputPanel styleClass="box1" style="border:none">
    <apex:dataTable columns="2" id="firstbox1" value="{!List}" var="p" rendered="{!(List!=null)}">
        <apex:column styleClass="c1">
            <apex:outputtext value="Profile Name"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Name}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Operating System"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.operating_system__c}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Application Development Language"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Application_Development_Language__c}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Database"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Database__c}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Web Server"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Web_Server__c}" style="width:250px"/>
        </apex:column>
        <apex:column styleClass="c1">
            <apex:outputtext value="Servlet Engine"/>
        </apex:column>
        <apex:column styleClass="c2">
            <apex:inputtext value="{!p.Servlet_Engine__c}" style="width:250px"/>
        </apex:column>
         <apex:column styleClass="bbox1">
                                                     <apex:column styleClass="bbox1">
              
<apex:commandButton value="Update" action="{!Save}" />
               </apex:column>
    </apex:dataTable>               
</apex:outputPanel>    
                     </apex:outputPanel>
        </apex:form>
   </apex:outputPanel>
</apex:page>

 

My controller is as follows:

 

public abstract class SubmitCaseController {

   
    public SubmitCaseController(ApexPages.StandardController controller) {
           }
    
   public List<Customer_Profile__c> cList{get;set;}
                 
   public PageReference Save(){
             update cList;
             return null;
   }
  
    
      public List<Customer_Profile__c> getList(){     
        cList = [select Id,Name,Application_Development_Language__c,Database__c,operating_system__c,Servlet_Engine__c,Web_Server__c from Customer_Profile__c where Account__r.Name =:accName];
              return cList;
    }        
    
     }

 

 

Can anyone please help me with this issue. Thanks in advance.

Hey all,

Made a lot of progress, and I'm almost there, just one last hitch. I am basically trying to emulate the inline editing in a list view posted about here.

 

http://salesforcesource.blogspot.com/2009/01/allow-mass-update-of-your-object.html

 

I have the list working, and the save event looks like it fires, but the changed data is not commited to the database. The ajax region updates, and no errors are tossed, but no data is commited. Any thoughts as to why? Below is my code.

 

 

Visualforce page

 

 

<apex:page controller="callListController" action="{!getData}">
    <apex:sectionHeader title="My Call List"></apex:sectionHeader>
    <apex:form >
        <apex:pageBlock title="">

          <!-- To show page level messages -->
          <apex:pageMessages ></apex:pageMessages>        
            <apex:pageBlockButtons >
                <apex:actionFunction action="{!UpdateRecords}" rerender="pageBlock" status="status"></apex:actionFunction>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!CampaignMembers}" var="cm">
                <apex:column value="{!cm.PID__c}"/>
                <apex:column value="{!cm.Caller__c}"/>
                <apex:column value="{!cm.Contact.phone}"/>
                <apex:column headerValue="Status">
                    <apex:inputField value="{!cm.Status}"/>
                </apex:column>
                <apex:column headerValue="Assign To Study">
                    <apex:outputText escape="false" value="{!cm.Add_To_Study__c}">
                    </apex:outputText>
                </apex:column>    
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:actionStatus startText="Saving..."/>
    </apex:form>    
</apex:page>

 

Controller

 

 

public class callListController 
{
    private List<CampaignMember> CampaignMembers;

    public List<CampaignMember> getCampaignMembers() 
    {
       return CampaignMembers;
       
    }        
    public void getData()
    {
            Map<string,string> params = ApexPages.currentPage().getParameters();
            Id campaignId = params.get('campaignId');
            Id userId = params.get('userid');
                
                

        CampaignMembers = [Select Token__c, 
                                          SystemModstamp, 
                                          Status, 
                                          Quick_Log_Call__c, 
                                          PID__c, 
                                          Orginization_Name__c, 
                                          LeadId, 
                                          LastModifiedDate, 
                                          LastModifiedById, 
                                          Id, 
                                          IVR_Contact_Attempts__c, 
                                          HasResponded, 
                                          FirstRespondedDate, 
                                          CreatedDate, 
                                          CreatedById, 
                                          ContactId,
                                          Contact.Phone, 
                                          CampaignId, 
                                          Caller__c, 
                                          Add_To_Study__c 
                                          From CampaignMember
                                          where caller__c = :userId and
                                          campaignID = :campaignId];          
    }

    public PageReference UpdateRecords()
    {
        update CampaignMembers;
        system.debug('Saving....');
        return null;
    }    
}