• oceanofstars
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 10
    Replies

Hi All

I have an Text field on user object which contains ID value of another object. I am trying to get that Text field in to an lookup field in account object. below is my trigger

trigger UpdateAccountUpsell on Opportunity (after update) {
List<Account> accountList= new List<Account>();
List<User> userList= new List<User>();

Set<Id> closedOpp= new set<Id>();

for (Opportunity opp: Trigger.new) {

if(Trigger.oldMap.get(opp.Id).StageName != 'Closed Won' && opp.StageName == 'Closed Won') {

closedOpp.add(opp.AccountId);

}

}


for (Account acc: [select Id, Owner.Split_Sales_Rep_ID__c, Commissionable_Upsell_Rep__c , of_Closed_Won_Opportunities__c from Account where Id IN :closedOpp]) {

if(acc.Commissionable_Upsell_Rep__c == ''){
acc.Commissionable_Upsell_Rep__c = acc.Owner.Split_Sales_Rep_ID__c;
}
update acc;
}

I am able to save the trigger but it is not updating the lookup field.

 

I wrote a trigger which compares old values and new values in it.  This trigger is sending http request to another system. Some values are updated to a new values by work flow rule. So, when we change some value trigger fires in sending the http request and work flow updates some fields. So, the trigger again fires after the work flow rules and sends the value through http request. but this times it is sending previous value and the values which are updated through work flow rule. So my question is, Is there any way to stop the sending previous value twice(first time trigger fires and the after workflow trigger fires again) or is there any way to fire a trigger just once after the workflow rules.

Hi 

 

I am trying to parse the wsdl in salesforce and get struck with this error

 

Failed to parse wsdl: attribute name can not be null at: 42:94. The following is the part of the WSDLand the line in red where the error is throwing.

 

<complexType name="ArrayOfReplyInfo">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="intf:ReplyInfo[]"/>
</restriction>
</complexContent>
</complexType>


public PageReference genProposa () {
        PageReference proposalPage = new PageReference('/apex/buildContractnew?Id=' + quote.Id);
        proposalPage.setRedirect(true);
        return proposalPage;

}

 

Hi I modify the above code to the below in order to stop creating proposal if the below condition is not satisfied. I am able to save the code but i can generate the proposal even if the below condition is not true. Can you please let me know where did i make the mistake. SSOW_product_Formula__c fields are null. Even if they are null i am able to generate a proposal. Actually it needs me to throw the error('test test test') if i click the generate proposal button

 

public PageReference genProposal() {
    PageReference proposalPage= new PageReference('/apex/buildProposal?Id=' + quote.Id);
    List<QuoteLine__c> q = [SELECT Id from QuoteLine__c WHERE Quote__c = :quote.Id AND SSOW_Product_Formula__c != ''];
    List <SSOW__c> sow = [Select Id From SSOW__c WHERE Quote__c = :Quote.Id AND Sales_Proposal_Fields_Complete__c = 'Yes'];
    If (sow.size()>0 && q.size()>0){
        
        proposalPage.setRedirect(true);
        }
    else{
        QuoteErrorMessages.add('test test test');
        }
        return proposalPage;
    }

Need help in save button: Whenwhen we are saving the records in VF page we are able to see the values but when we open the record again and see we are unable to see the values. This is my class 

 

public class SSOWcontrollers{ 

ApexPages.StandardController controller;
Public SSOW__c ssow;
Public SSOWcontrollers(ApexPages.StandardController stdController) {}
    public void savessow()
    {
    String sId = ApexPages.currentPage().getParameters().get('id');
        SSOW__C sow = [SELECT Id FROM SSOW__c WHERE Id= :sId];
        if (sow != null) {
        update sow;
        }
        HVoIP__c hv = [SELECT Id FROM HVoIP__c WHERE SSOW__c = :sId];
        if (hv != null) {
        update hv;
        }
        VoIP__c v = [SELECT Id FROM VoIP__c WHERE SSOW__c = :sId];
        if (v != null) {
        update v;
        }
        VLS__c vl = [SELECT Id FROM VLS__c WHERE SSOW__c = :sId];
        if (vl != null) {
        update vl;
        }
        VPN__c vp = [SELECT Id FROM VPN__c WHERE SSOW__c = :sId];
        if (vp != null) {
        update vp;
        }
        EIA__c e = [SELECT Id FROM EIA__c WHERE SSOW__c = :sId];
        if (e != null) {
        update e;
        }
        DIA__c d = [SELECT Id FROM DIA__c WHERE SSOW__c = :sId];
        if (d != null) {
        update d;
        }
        Managed_Network_Security__c mns = [SELECT Id FROM Managed_Network_Security__c WHERE SSOW__c = :sId];
        if (mns != null) {
        update mns;
        }
        Managed_Router__c mr = [SELECT Id FROM Managed_Router__c WHERE SSOW__c = :sId];
        if (mr != null) {
        update mr;
        }
     }

}
     Here is the part of the vf page where i created a save button

 

<apex:pageBlockButtons location="TOP" > 

<apex:commandButton id="theButton" action="{!savessow}" value="save"  />           

</apex:pageBlockButtons>    

Quote__c is lookup in SSOW__c. I am trying to get a id for a visualforce page. My code is paste below and this the error it is throwing

This is the part of the code. I defined SSOW intially in my code as

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<SSOW__c>

 

public List<SSOW__c>SSOWs{get; set;}

public PageReference genSSOW() {
     SSOWs=[select Id from SSOW__c where Quote__c =:quote.Id Limit 1];
        PageReference ssowPage= new PageReference('/apex/Smartsow?Id=' +SSOWs.Id);
        SSOWPage.setRedirect(true);
        return SSOWPage;
    }


   

Hi All I have one class. I wrote a test class for that its save but when run test i m getting error like this 

 

System.QueryException: List has no rows for assignment to SObjectClass.MagnysApprovalController.<init>: line 9, column 10 Class.Test_Pages.testMagnysApprovalController: line 24, column 46 External entry point

My class is 

public with sharing class MagnysApprovalController{
    Private string comment = '';
    public String oppId= ApexPages.currentPage().getParameters().get('OppId');
    public Opportunity o;
    public List<Quote__c> qlist;
    public Quote__c q;
    public List<QuoteLine__c> TempQuoteLine;
    public MagnysApprovalController(){
      o = [select Id, Name, Owner.Name, Owner.Employee_ID__c, AccountId, Account.Name, Scope_of_Work__c, Existing_Services_Replaced__c, Amount from Opportunity
                 where id= :oppId];
       qlist = [Select Id, Total_Quote_Amount__c, Primary__c, Opportunity__c, Name, Contract_Term__c, Contract_Start_Date__c, AverageDiscountPercentage__c From Quote__c 
                where Opportunity__c = :oppId and Primary__c = true limit 1];
      if( qlist.size()>0 ){
        q = qlist.get(0);
          TempQuoteLine = [select id, MasterProduct__c, Total_Sale__c, MagnysServiceCode__c, MagnysRevenue__c, Term__c, Previous_Price__c, MasterProduct__r.Name, MagnysServiceCode__r.Name from QuoteLine__c where Quote__c = :q.Id];
      }  
    } 
    public Opportunity getOpp(){
        return o; 
    }
    public Quote__c getQuote(){
        return q;
    }
    public List<QuoteLine__c> getqlList(){
        return TempQuoteLine;    
    }
    public string getComment()
    {
        return comment;
    }
    public void setComment(string Value){
        comment= Value;
    }
    public PageReference reject() {
        PageReference pr = null;
        try{        
            ProcessInstanceWorkitem piwi = [Select ProcessInstance.Status, ProcessInstance.TargetObjectId, ProcessInstanceId,OriginalActorId,Id,ActorId From ProcessInstanceWorkitem
            where ProcessInstance.TargetObjectId = : oppId and ProcessInstance.Status = 'Pending' and OriginalActorId =: UserInfo.getUserId() order by CreatedDate desc limit 1];    
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
            req.setComments(comment);
            req.setAction('Reject');
            req.setWorkitemId(piwi.Id);
            // Submit the request for approval      
            Approval.ProcessResult result =  Approval.process(req);        
            pr = new PageReference('/home/home.jsp');
        }
        catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
        }
        return pr;
    }
  public PageReference reject1() {
        PageReference pr = null;
        try{        
            ProcessInstanceWorkitem piwi = [Select ProcessInstance.Status, ProcessInstance.TargetObjectId, ProcessInstanceId,OriginalActorId,Id,ActorId From ProcessInstanceWorkitem
            where ProcessInstance.TargetObjectId = : oppId and ProcessInstance.Status = 'Pending' and OriginalActorId =: UserInfo.getUserId() order by CreatedDate desc limit 1];
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
            req.setComments(comment);
            req.setAction('Reject');
            req.setWorkitemId(piwi.Id);
            // Submit the request for approval      
            Approval.ProcessResult result =  Approval.process(req);        
            //pr = new PageReference('/home/home.jsp');
            pr = new PageReference('/apex/mobileApprovalList?sfdc.tabName=01r40000000LnKP');
        }
        catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
        }
        return pr;
    }
    public PageReference approve(){
        PageReference pr = null;
        try{  
            ProcessInstanceWorkitem piwi = [Select ProcessInstance.Status, ProcessInstance.TargetObjectId, ProcessInstanceId,OriginalActorId,Id,ActorId From ProcessInstanceWorkitem
            where ProcessInstance.TargetObjectId = : oppId and ProcessInstance.Status = 'Pending' and OriginalActorId =: UserInfo.getUserId() order by CreatedDate desc limit 1];
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
            req.setComments(comment);
            req.setAction('Approve');
            req.setWorkitemId(piwi.Id);
            // Submit the request for approval      
            Approval.ProcessResult result =  Approval.process(req);
            pr = new PageReference('/home/home.jsp');
        }
        catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
        }
        return pr;
    }
    public PageReference approve1(){
        PageReference pr = null;
        try{  
            ProcessInstanceWorkitem piwi = [Select ProcessInstance.Status, ProcessInstance.TargetObjectId, ProcessInstanceId,OriginalActorId,Id,ActorId From ProcessInstanceWorkitem
            where ProcessInstance.TargetObjectId = : oppId and ProcessInstance.Status = 'Pending' and OriginalActorId =: UserInfo.getUserId() order by CreatedDate desc limit 1];
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
            req.setComments(comment);
            req.setAction('Approve');
            req.setWorkitemId(piwi.Id);
            // Submit the request for approval      
            Approval.ProcessResult result =  Approval.process(req);
            //pr = new PageReference('/home/home.jsp');
            pr = new PageReference('/apex/mobileApprovalList?sfdc.tabName=01r40000000LnKP');
        }
        catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
        }
        return pr;
    }     
}

 

And test class is 

 

  public static testMethod void testMagnysApprovalController() 
    {      
        Test.startTest();
        PageReference result = Page.MagnysApproval;
        Test.setCurrentPage(result);
                        
        Account account= new Account(Name='Test Account', Type='Standard Account', Federal_Tax_ID_No__c='01010101', 
        Main_BTN__c='(000)000-7654', ShippingStreet='000 Test St', ShippingCity='Dallas', 
        ShippingState='Tx', ShippingPostalCode='75050');
        insert account; 
       
        Opportunity opp = new Opportunity(Name='Test Opp1', Existing_Services_Replaced__c = 'none', AccountId=account.Id, Scope_of_Work__c='Test', 
        Proposal_Issued_Date__c=Date.Today(), StageName='Closed Won',CloseDate=System.today());
        insert opp;
        
        Quote__c q = new Quote__c(Contract_Term__c = '12',Name='Test',Opportunity__c = opp.id);
        insert q;
        Profile p = [select id from Profile limit 1];
         User u = new User(ProfileId = p.id,LastName = 'Test', FirstName = 'Test', Username = 'testing456@test.com', Alias='test', CommunityNickname='test', Email='test@email.com',TimeZoneSidKey='America/Chicago',EmailEncodingKey='ISO-8859-1', LanguageLocaleKey='en_US', LocaleSidKey='en_US',IsActive=false);
                
        insert u;
         
 
        MagnysApprovalController extension = new MagnysApprovalController();
    
        extension.getComment(); 
        extension.reject();
        extension.reject1();
        extension.approve();
        extension.approve1();              
    }  
    

 

Hi All
I have an object called company profile. It has only 3 fields in it. Account, Telephone,company details. Now my scenario is whenever anybody creates a new company profile and add a telephone no and if it matches to any account phone then it should display that account in account field in the company profile object.Account is the lookup in the company profile. Here is the trigger i wrote i am able to save the trigger but when i create a record it is saying nullvalue on line 21. I mentioned the line 21 in RED below. Please have a look at it and let me know where did i make a mistake
trigger relatedaccount on companyprofile__c (after insert, after update) {
Map<String, companyprofile__c> mapPhones = new Map<String, companyprofile__c>();
    for (companyprofile__c c: Trigger.new) { 
        if (c.telephone__c != null) {
            mapPhones.put(c.telephone__c, c);
        }
    }
     List<String> listPhones = new List<String>();
    Map<String, Account> mapAccounts = new Map<String, Account>();
    for (list<Account> acts : [Select Id, phone__c from Account where phone__c in :listPhones]) {
        for (Account act : acts) {
            mapAccounts.put(act.phone__c, act);
        }
    }
    // Creating a List of companyprofile__c which will be inserted at the end.
    List<companyprofile__c> listcompanyprofiles = new List<companyprofile__c>();
    for (companyprofile__c c: mapPhones.values()) {
        companyprofile__c ca = new companyprofile__c(Name = c.Name); 
        ca.Account__c = mapAccounts.get(c.telephone__c).ID; 
        listcompanyprofiles.add(ca);
    }
    update listcompanyprofiles;
}

 

Hi All

 

We have our custom build quote tool. From quote tool we have a button called CLOSED WON where we can close the opportunity. If any body wants to change something in the quote they need to change the opportunity stage from closed won to a different page from opportunity and then they can make some changes in the quote and can hit CLOSE WON button from quote.

 

Now i want to display a warning message when anybody try to change some information in the quote for the CLOSE/WON opportunities..want to display as this opportunity went to different environment and any changes will not effect immediately. After displaying this mess the sales rep can save the opportunity or can cancel the changes. Please help me out how can this be done. Appreciate your help in advance

 

 

Hi All

 

I am trying to create a visual force Email template. I wanted to add custom object fields in the email template. I created a apex controller, component and i called the component in to VF page template but still unable to find out the custom fields in the VF template which i added in the component. Here is the thing i did

 

Controller

 

public class CAFApprovalHistoryController {
   public CAF__c cf;
    public String cafId {get;set;}
    public List<ProcessInstanceHistory> getApprovalSteps() {
      if (cafId != null) {
        CAF__c cafs = [Select Id, Name, CAPEX_Total__c, Off_Net_Circuit_Expense_Total__c, CAF_IRR__c, of_Revisions__c, Sales_Rep__c, Sales_Manager__c, Account__c, CAF_Title1_del__c, CAF_1__c, Products_Requested__c, Bandwidth__c, Notes_of_Consideration__c, CAF_Link__c, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from CAF__c where Id = :cafId];
        return cafs.ProcessSteps;
      }
      return new List<ProcessInstanceHistory> ();
    }
  public CAF__c getcaf(){
  return cf;
  }
 }

 

Component. Blue are the custom object fields which i added in the component. But, i am unable to see those in the VF email template

 

<apex:component controller="CAFApprovalHistoryController" access="global">
    <apex:attribute name="cafId" assignTo="{!cafId}" type="String" description="Id of the CAF"/> 
    <apex:dataTable value="{!approvalSteps}" var="step">
        <apex:column value="{!step.SystemModstamp}" headerValue="Date"/>
        <apex:column value="{!step.StepStatus}" headerValue="Status"/>
        <apex:column value="{!step.OriginalActorId}" headerValue="Assigned To"/>
        <apex:column value="{!step.ActorID}" headerValue="Actual Approver"/>
        <apex:column value="{!step.Comments}" headerValue="Comments"/>
        <apex:outputLabel value="CAF" for="CAF__c.CAFId">
        <apex:pageBlockSection >
        <apex:outputField id="CAPEX" value="{!CAF.CAPEX_Total__c}"/>
        <apex:outputField id="OffNetCircuitExpense" value="{!CAF.Off_Net_Circuit_Expense_Total__c}"/>
        <apex:outputField id="SalesManager" value="{!CAF.Sales_Manager__c}"/>
        </apex:pageBlockSection>
       
         
       
        </apex:outputLabel>
    </apex:dataTable>
</apex:component>

 

And i called the above component in the VF template mentioned in Red in the below code. Here is my VF Template.

 

<messaging:emailTemplate subject="Your CAF has been Rejected" recipientType="User" relatedToType="CAF__c">
<messaging:HtmlEmailBody >
Rejected!
<br/>
Your CAF has been rejected.
<br/>
Below are the approval rejection comments
<html>
<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
    <meta name="Template" content="Response"/>
</head>
<body>
<br/>
<b>Capital Planning will follow up on the rejection of this CAF.  Please do not reply to this e-mail.</b>
<br/>
<b>CAF Details</b>
<br/>
<p><b>Approval History</b>
<c:CAF_Approval_History_Component cafId="{!relatedTo.Id}"/>
</p>
</body>
</html>
</messaging:HtmlEmailBody>
</messaging:emailTemplate>

 

 

 

 

 

 

Hi i wrote a trigger its hiting govener limit for soql query limi101 so can any one hlp me

 

trigger ProductInsert on Product2 (after insert)
{
    //declarations 
    PricebookEntry[] newPBEntry = new PricebookEntry[0];
   
    //get the active standard pricebook
    Pricebook2 standardPB = [select id from pricebook2 where isstandard = true and isactive = true limit 1];
   
    //  create a list of the new productids
    Set<Id> pIds = new Set<Id>();
        for(Product2 pId:Trigger.new)
    {
        pIds.add(pId.Id);      
    } 
   
    //existing pb map, this is for when a record is cloned, it will also clone the pb and we dont need to create it
    Map<Id, PricebookEntry> existingPBMap = new Map<Id, PricebookEntry>();
    for(PricebookEntry ePB:[select id, Product2Id from PricebookEntry where Pricebook2Id = :standardPB.Id
            and Product2Id in :pIds])
    {
            existingPBMap.put(ePB.Product2Id, ePB);
    }
       
   
    //loop through products
    for(Product2 p:Trigger.new)
    {
        if(existingPBMap.get(p.Id) == null)
        {
            PricebookEntry pb = new PricebookEntry();
            pb.UnitPrice = 0;          
            pb.Product2Id = p.Id;
            pb.Pricebook2Id = standardPB.Id;
            pb.IsActive = true;
            newPBEntry.add(pb);
        }
    }
   
    //create the pricebookentry records
    insert newPBEntry;
}

 

in red color soql query is hiting a limit can any one plz help me

 

Thanks

One of my developer create a trigger using this

 

String userName = UserInfo.getUserName();
if(UserName!='test@test.com')

 

so trigger dont fire for this user.

Now i wann to create a trigger. it should not fire when product2 has one field call NPA_NXX__c has some particular value

 

what should i do in order not to fire the tigger.

Hi All

 

Can you please help me in writing a test class for the following trigger. The scenario is whenever an opportunity is closed won or dead/lost a field should be updated in Case object.

 

trigger CaseUpadate on Opportunity (after update)
{
List <Case> caseList;
List <Id> oppIdList = new List <Id>();
for(Integer i=0; i<Trigger.new.size(); i++)
{
    if (Trigger.new[i].StageName != Trigger.old[i].StageName && (Trigger.new[i].StageName == 'Closed Won' || Trigger.new[i].StageName == 'Closed - Dead/Lost'))
       
        oppIdList.add(Trigger.new[i].Id);
}  
caseList = [select Id, Opportunity_closed_won__c from Case where Opportunity__c in :oppIdList];
if (caseList.size() > 0)
{
    for(Case c : caseList)
    {
        if (c.Opportunity_closed_won__c != true)
            c.Opportunity_closed_won__c = true;   
    }
   
    update caseList;
    }
}

Need help in save button: Whenwhen we are saving the records in VF page we are able to see the values but when we open the record again and see we are unable to see the values. This is my class 

 

public class SSOWcontrollers{ 

ApexPages.StandardController controller;
Public SSOW__c ssow;
Public SSOWcontrollers(ApexPages.StandardController stdController) {}
    public void savessow()
    {
    String sId = ApexPages.currentPage().getParameters().get('id');
        SSOW__C sow = [SELECT Id FROM SSOW__c WHERE Id= :sId];
        if (sow != null) {
        update sow;
        }
        HVoIP__c hv = [SELECT Id FROM HVoIP__c WHERE SSOW__c = :sId];
        if (hv != null) {
        update hv;
        }
        VoIP__c v = [SELECT Id FROM VoIP__c WHERE SSOW__c = :sId];
        if (v != null) {
        update v;
        }
        VLS__c vl = [SELECT Id FROM VLS__c WHERE SSOW__c = :sId];
        if (vl != null) {
        update vl;
        }
        VPN__c vp = [SELECT Id FROM VPN__c WHERE SSOW__c = :sId];
        if (vp != null) {
        update vp;
        }
        EIA__c e = [SELECT Id FROM EIA__c WHERE SSOW__c = :sId];
        if (e != null) {
        update e;
        }
        DIA__c d = [SELECT Id FROM DIA__c WHERE SSOW__c = :sId];
        if (d != null) {
        update d;
        }
        Managed_Network_Security__c mns = [SELECT Id FROM Managed_Network_Security__c WHERE SSOW__c = :sId];
        if (mns != null) {
        update mns;
        }
        Managed_Router__c mr = [SELECT Id FROM Managed_Router__c WHERE SSOW__c = :sId];
        if (mr != null) {
        update mr;
        }
     }

}
     Here is the part of the vf page where i created a save button

 

<apex:pageBlockButtons location="TOP" > 

<apex:commandButton id="theButton" action="{!savessow}" value="save"  />           

</apex:pageBlockButtons>    

Quote__c is lookup in SSOW__c. I am trying to get a id for a visualforce page. My code is paste below and this the error it is throwing

This is the part of the code. I defined SSOW intially in my code as

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<SSOW__c>

 

public List<SSOW__c>SSOWs{get; set;}

public PageReference genSSOW() {
     SSOWs=[select Id from SSOW__c where Quote__c =:quote.Id Limit 1];
        PageReference ssowPage= new PageReference('/apex/Smartsow?Id=' +SSOWs.Id);
        SSOWPage.setRedirect(true);
        return SSOWPage;
    }


   

Hi All I have one class. I wrote a test class for that its save but when run test i m getting error like this 

 

System.QueryException: List has no rows for assignment to SObjectClass.MagnysApprovalController.<init>: line 9, column 10 Class.Test_Pages.testMagnysApprovalController: line 24, column 46 External entry point

My class is 

public with sharing class MagnysApprovalController{
    Private string comment = '';
    public String oppId= ApexPages.currentPage().getParameters().get('OppId');
    public Opportunity o;
    public List<Quote__c> qlist;
    public Quote__c q;
    public List<QuoteLine__c> TempQuoteLine;
    public MagnysApprovalController(){
      o = [select Id, Name, Owner.Name, Owner.Employee_ID__c, AccountId, Account.Name, Scope_of_Work__c, Existing_Services_Replaced__c, Amount from Opportunity
                 where id= :oppId];
       qlist = [Select Id, Total_Quote_Amount__c, Primary__c, Opportunity__c, Name, Contract_Term__c, Contract_Start_Date__c, AverageDiscountPercentage__c From Quote__c 
                where Opportunity__c = :oppId and Primary__c = true limit 1];
      if( qlist.size()>0 ){
        q = qlist.get(0);
          TempQuoteLine = [select id, MasterProduct__c, Total_Sale__c, MagnysServiceCode__c, MagnysRevenue__c, Term__c, Previous_Price__c, MasterProduct__r.Name, MagnysServiceCode__r.Name from QuoteLine__c where Quote__c = :q.Id];
      }  
    } 
    public Opportunity getOpp(){
        return o; 
    }
    public Quote__c getQuote(){
        return q;
    }
    public List<QuoteLine__c> getqlList(){
        return TempQuoteLine;    
    }
    public string getComment()
    {
        return comment;
    }
    public void setComment(string Value){
        comment= Value;
    }
    public PageReference reject() {
        PageReference pr = null;
        try{        
            ProcessInstanceWorkitem piwi = [Select ProcessInstance.Status, ProcessInstance.TargetObjectId, ProcessInstanceId,OriginalActorId,Id,ActorId From ProcessInstanceWorkitem
            where ProcessInstance.TargetObjectId = : oppId and ProcessInstance.Status = 'Pending' and OriginalActorId =: UserInfo.getUserId() order by CreatedDate desc limit 1];    
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
            req.setComments(comment);
            req.setAction('Reject');
            req.setWorkitemId(piwi.Id);
            // Submit the request for approval      
            Approval.ProcessResult result =  Approval.process(req);        
            pr = new PageReference('/home/home.jsp');
        }
        catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
        }
        return pr;
    }
  public PageReference reject1() {
        PageReference pr = null;
        try{        
            ProcessInstanceWorkitem piwi = [Select ProcessInstance.Status, ProcessInstance.TargetObjectId, ProcessInstanceId,OriginalActorId,Id,ActorId From ProcessInstanceWorkitem
            where ProcessInstance.TargetObjectId = : oppId and ProcessInstance.Status = 'Pending' and OriginalActorId =: UserInfo.getUserId() order by CreatedDate desc limit 1];
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
            req.setComments(comment);
            req.setAction('Reject');
            req.setWorkitemId(piwi.Id);
            // Submit the request for approval      
            Approval.ProcessResult result =  Approval.process(req);        
            //pr = new PageReference('/home/home.jsp');
            pr = new PageReference('/apex/mobileApprovalList?sfdc.tabName=01r40000000LnKP');
        }
        catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
        }
        return pr;
    }
    public PageReference approve(){
        PageReference pr = null;
        try{  
            ProcessInstanceWorkitem piwi = [Select ProcessInstance.Status, ProcessInstance.TargetObjectId, ProcessInstanceId,OriginalActorId,Id,ActorId From ProcessInstanceWorkitem
            where ProcessInstance.TargetObjectId = : oppId and ProcessInstance.Status = 'Pending' and OriginalActorId =: UserInfo.getUserId() order by CreatedDate desc limit 1];
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
            req.setComments(comment);
            req.setAction('Approve');
            req.setWorkitemId(piwi.Id);
            // Submit the request for approval      
            Approval.ProcessResult result =  Approval.process(req);
            pr = new PageReference('/home/home.jsp');
        }
        catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
        }
        return pr;
    }
    public PageReference approve1(){
        PageReference pr = null;
        try{  
            ProcessInstanceWorkitem piwi = [Select ProcessInstance.Status, ProcessInstance.TargetObjectId, ProcessInstanceId,OriginalActorId,Id,ActorId From ProcessInstanceWorkitem
            where ProcessInstance.TargetObjectId = : oppId and ProcessInstance.Status = 'Pending' and OriginalActorId =: UserInfo.getUserId() order by CreatedDate desc limit 1];
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
            req.setComments(comment);
            req.setAction('Approve');
            req.setWorkitemId(piwi.Id);
            // Submit the request for approval      
            Approval.ProcessResult result =  Approval.process(req);
            //pr = new PageReference('/home/home.jsp');
            pr = new PageReference('/apex/mobileApprovalList?sfdc.tabName=01r40000000LnKP');
        }
        catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
        }
        return pr;
    }     
}

 

And test class is 

 

  public static testMethod void testMagnysApprovalController() 
    {      
        Test.startTest();
        PageReference result = Page.MagnysApproval;
        Test.setCurrentPage(result);
                        
        Account account= new Account(Name='Test Account', Type='Standard Account', Federal_Tax_ID_No__c='01010101', 
        Main_BTN__c='(000)000-7654', ShippingStreet='000 Test St', ShippingCity='Dallas', 
        ShippingState='Tx', ShippingPostalCode='75050');
        insert account; 
       
        Opportunity opp = new Opportunity(Name='Test Opp1', Existing_Services_Replaced__c = 'none', AccountId=account.Id, Scope_of_Work__c='Test', 
        Proposal_Issued_Date__c=Date.Today(), StageName='Closed Won',CloseDate=System.today());
        insert opp;
        
        Quote__c q = new Quote__c(Contract_Term__c = '12',Name='Test',Opportunity__c = opp.id);
        insert q;
        Profile p = [select id from Profile limit 1];
         User u = new User(ProfileId = p.id,LastName = 'Test', FirstName = 'Test', Username = 'testing456@test.com', Alias='test', CommunityNickname='test', Email='test@email.com',TimeZoneSidKey='America/Chicago',EmailEncodingKey='ISO-8859-1', LanguageLocaleKey='en_US', LocaleSidKey='en_US',IsActive=false);
                
        insert u;
         
 
        MagnysApprovalController extension = new MagnysApprovalController();
    
        extension.getComment(); 
        extension.reject();
        extension.reject1();
        extension.approve();
        extension.approve1();              
    }  
    

 

Hi All
I have an object called company profile. It has only 3 fields in it. Account, Telephone,company details. Now my scenario is whenever anybody creates a new company profile and add a telephone no and if it matches to any account phone then it should display that account in account field in the company profile object.Account is the lookup in the company profile. Here is the trigger i wrote i am able to save the trigger but when i create a record it is saying nullvalue on line 21. I mentioned the line 21 in RED below. Please have a look at it and let me know where did i make a mistake
trigger relatedaccount on companyprofile__c (after insert, after update) {
Map<String, companyprofile__c> mapPhones = new Map<String, companyprofile__c>();
    for (companyprofile__c c: Trigger.new) { 
        if (c.telephone__c != null) {
            mapPhones.put(c.telephone__c, c);
        }
    }
     List<String> listPhones = new List<String>();
    Map<String, Account> mapAccounts = new Map<String, Account>();
    for (list<Account> acts : [Select Id, phone__c from Account where phone__c in :listPhones]) {
        for (Account act : acts) {
            mapAccounts.put(act.phone__c, act);
        }
    }
    // Creating a List of companyprofile__c which will be inserted at the end.
    List<companyprofile__c> listcompanyprofiles = new List<companyprofile__c>();
    for (companyprofile__c c: mapPhones.values()) {
        companyprofile__c ca = new companyprofile__c(Name = c.Name); 
        ca.Account__c = mapAccounts.get(c.telephone__c).ID; 
        listcompanyprofiles.add(ca);
    }
    update listcompanyprofiles;
}

 

Hi All

 

We have our custom build quote tool. From quote tool we have a button called CLOSED WON where we can close the opportunity. If any body wants to change something in the quote they need to change the opportunity stage from closed won to a different page from opportunity and then they can make some changes in the quote and can hit CLOSE WON button from quote.

 

Now i want to display a warning message when anybody try to change some information in the quote for the CLOSE/WON opportunities..want to display as this opportunity went to different environment and any changes will not effect immediately. After displaying this mess the sales rep can save the opportunity or can cancel the changes. Please help me out how can this be done. Appreciate your help in advance

 

 

Hi i wrote a trigger its hiting govener limit for soql query limi101 so can any one hlp me

 

trigger ProductInsert on Product2 (after insert)
{
    //declarations 
    PricebookEntry[] newPBEntry = new PricebookEntry[0];
   
    //get the active standard pricebook
    Pricebook2 standardPB = [select id from pricebook2 where isstandard = true and isactive = true limit 1];
   
    //  create a list of the new productids
    Set<Id> pIds = new Set<Id>();
        for(Product2 pId:Trigger.new)
    {
        pIds.add(pId.Id);      
    } 
   
    //existing pb map, this is for when a record is cloned, it will also clone the pb and we dont need to create it
    Map<Id, PricebookEntry> existingPBMap = new Map<Id, PricebookEntry>();
    for(PricebookEntry ePB:[select id, Product2Id from PricebookEntry where Pricebook2Id = :standardPB.Id
            and Product2Id in :pIds])
    {
            existingPBMap.put(ePB.Product2Id, ePB);
    }
       
   
    //loop through products
    for(Product2 p:Trigger.new)
    {
        if(existingPBMap.get(p.Id) == null)
        {
            PricebookEntry pb = new PricebookEntry();
            pb.UnitPrice = 0;          
            pb.Product2Id = p.Id;
            pb.Pricebook2Id = standardPB.Id;
            pb.IsActive = true;
            newPBEntry.add(pb);
        }
    }
   
    //create the pricebookentry records
    insert newPBEntry;
}

 

in red color soql query is hiting a limit can any one plz help me

 

Thanks