• Dayakar.D
  • SMARTIE
  • 1079 Points
  • Member since 2015

  • Chatter
    Feed
  • 24
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 52
    Replies
Hi,

Im having alot of difficulty with this some Apex Code

Im trying to Query Opportunities that are Opp Enquiry Source contains referrals and the event on it is a Sat On Appointment. So i can get a count of them in visualforce.

I know how to display counts in visualforce, I know how to query singular objects for these results but because of the information is on an event and some is on an opportunity I have come to a sticking point.

I thought i might have been able to do this with I was previously advised to do it via this
What.Opp_Enquiry_Source LIKe :IsRef
However this doesnt work and comes up with 

No such column 'Opp_Enquiry_Source__c' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. Is this because of how the What field works on events. That field defiantly exists ive used it previously but its not working

I thought maybe this the following would work 
return [SELECT Count()
            FROM Opportunity o,o.Event e
WHERE o.Opp_Enquiry_Source__c LIKe :IsRef AND e.Sat_On__c = TRUE
Ive tried this both ways so Event e, e.Opportunity o and Opportunity o,o.Event e

I get this as error 

Didn't understand relationship 'e.Opportunity' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Thank you in advance


 

We have a visualforce page and apex to handle configuration of our line items on an opportunity.  How do we restrict updating of the line item fields to only allow update of these records by code?   We don't want the users to update these fields manually.  

We can't change the CRUD permissions to read only because they won't be able to update via the code. 

Can this be accomplished with validation rules or triggers?

Hello. I have a custom object contractor__c child object under opportunity. If a contractor__c is created, I need to make sure one and only one contractor__c is marked as primary for the opportunity. I tried an Apex trigger like this but it's not working. If I set the first contractor as primary, it will also set the second contractor as primary. And if I turn the primary flag off for the first contractor, it does not turn on the primary flag for the second contractor. Any help is appreciated.
 
trigger VerifyOnlyOnePrimaryContractor on Contractor__c (before insert, before update) {
    
    for(Contractor__c c: trigger.new){
        string O = c.Opportunity__c;
        string thisContractor = c.ID;
        //if this contractor is marked primary, make all the others for the same opportunity not primary
        if(c.Primary__c){
            List<contractor__c> cList = [Select id from Contractor__c where Opportunity__c = :O and id <> :thisContractor];
            
            for(contractor__c con : cList){
                con.Primary__c = FALSE;
            }
            update cList;
        }
        
        else{
            //if no contractors are marked as primary, set one of them as primary
            string primary = 'no';
            List<contractor__c> cList1 = [Select id,primary__c from Contractor__c where Opportunity__c = :O];
            if(cList1.size() == 0){
                c.Primary__c = TRUE;
            }
            else
            {
                for(contractor__c con1 : cList1){
                    if(con1.Primary__c){
                        primary = 'yes';
                    }
                }
                if(primary == 'no'){
                    
                    c.Primary__c = TRUE;
                }
            }
        }
        
    }                                                                                                                                                                                                       
}

 
There is two object: Fund and opportunity. and opportunity object has lookup of Fund. I've devloped one trigger that sum up the total amount from all the relative opportunity and set that amount in custom field of fund object. now problem in my code is that whenever I try to create bulk opportunity using CSV file that contain data for multiple fund at that time it sum up the total of all fund and set that only in first record fund ID. I need solution using Map.
Thannk you.

Trigger:
trigger newLeadTrigger on Opportunity (after insert , after update, after delete , after undelete) {
    
    if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate || trigger.isUndelete)){
           OpportunityCustomRollup.CountRollup(Trigger.new);
    }
    
    if(Trigger.isDelete)
    {
        OpportunityCustomRollup.CountRollup(Trigger.old);
    }
}


Controller class:

public class OpportunityCustomRollup {
   
    public static void CountRollup(List<Opportunity> lstOpportunity){
        
        set<id> oppIds = new set<id>();
        map<string, integer> classroomIDToDeskCountMap = new map<string, integer>();
        id objrecordtypeid = [SELECT Id FROM RecordType WHERE DeveloperName ='Fund_Raising'].Id;
        double amount = 0;
        
        try {
                for (Opportunity objOpportunity : lstOpportunity){
                    oppIds.add(objOpportunity.Fund__c);
                }
            
                Fund__c objfund = [SELECT Id, Total_opportunity_amount__c  FROM Fund__c WHERE Id = :oppIds];
                List<Opportunity> list_Opportunity = [SELECT Id, Amount FROM Opportunity WHERE Fund__c = :objfund.Id and StageName = 'Closed Won' and RecordTypeId =: objrecordtypeid];
            
            
                 for(Opportunity AmountOpportunity : list_Opportunity) {
                        amount += AmountOpportunity.amount; 
                 }
            
            
                  objfund.Total_opportunity_amount__c = amount;
                  update objfund;   
            } 
       
        
        catch (Exception e) {
                System.debug(e);
            }
        
    }

}
  
Hi All,

I have a Comments field of Type LongTextArea(Size 256). when i use this field in reports i am getting 253 characters and dots(..) . I am not even getting 254 characters. I just want to display full text from comments field. Any body can help me to solve this problem.
Hi all, 

Need to capture  user/jobs details who updated case  in both before update (Before update record) , after update(who updated ) ?
need to store  last 30 days records modified user details and modified 10 field values future reference. 

can you please assist me with trigger code. 

 

Hi,

I'm looking into creating a process in which Salesforce will update the parent record if a field on the child has the value 'Rejected'.

So we have a parent object - Offer and child - Offer SIte.
Then if the field Status__c on Offer Site = 'Rejected', I want to apply the same value to a field called Status on Offer automatically once the field on Offer site is updated.

Does anyone know how to do this?
I'm not too sure on how I can write this into trigger as my experience with triggers is basic

Any help is much appreciated.
Thanks.

Hello,

I have a checkbox on Account object "CustomCheck__c"

In the quote, i have a custom button
User-added image
window.location.href='/apex/QUOTES__Quote_Get?&id={!Quote.Id}&retURL=//{!Quote.Id}&cancelURL={!Quote.Id}';

I want to execute this URL only when the checkbox on Account is unticked else display an error message 

How can i acheive it ?

thanks for suggestions
  • May 05, 2017
  • Like
  • 0
I have just started coding in Apex and in the very begining  I have got an error.

Error - Line: 2, Column: 4
Variable does not exist: name
User-added image
Hi all,
can any one help on this .
 
public pageReference searchProducts(){
        Map<String,Object> fieldValuesMap =new Map<String,Object> ();
        
        String query = 'select id'; 
        System.debug('query first ------>'+query );
        string WhereClause;
        for(Schema.FieldSetMember f : SObjectType.Product2.FieldSets.SearchProducts.getFields()) 
        {
            query += ', ' + f.getFieldPath();  
            WhereClause=''+schema.product2.getSobjectType()+' LIKE \'%'+ f.getFieldPath() + '%\'  ';
            System.debug('WhereClause ------>'+WhereClause );
        }
        query += ' FROM Product2 WHERE ' +WhereClause;
        
        System.debug('query ------>'+query );
        Products = Database.query(query);
        System.debug('Products ------>'+Products );
         
        for(Schema.FieldSetMember f : SObjectType.Product2.FieldSets.ProductFields.getFields()) 
        {
            
            WhereClause='id=:Product2.id ,Product2.'+f.getfieldPath()+' LIKE \'%'+ f.getFieldPath() + '%\'  ';
            System.debug('WhereClause ------>'+WhereClause );
        }
        WhereClause += ' FROM Product2 WHERE ' +WhereClause; 
        
        System.debug('query ------>'+query );
        Products = Database.query(query);
        System.debug('Products $$$$$ ------>'+Products );
        query=Query +'From Product2'+WhereClause;
        System.debug('query $$$$$ ------>'+query );
        return Null;
    }

in this method am not able to get the product values in search functionality
 
Hi Experts,
I need to create a trigger on account object which will prevent the users in creating duplicate account based on the name.
Kindly provide me the same.

Regards.
Hello Team ,

Need help to overcome the situation, please help.

I've a custom object that contains customer information like customer name, address etc. I have few other fields on this object named Recipient, Recipient Name, Recipient Address. The recipient is a Picklist field which contains values like "Myself" , "Other" . Now the requirement is 

1> If user select "Myself" , then Recipient Name, Recipient Address should become read only and copy values from customer name, address. 
2> If user selects Other, then he can type Recipient Name, Recipient Address by his choice. 

Can someone guide me to how to achieve this, please ?

Thanks,
TG
Hi Friends,

I write a program on javascript base. When i give the less than 3 letters user name it wil display error msg. But its not working and also F1 is not woking. Please check this code and help me to solve this problem,

Code:


<apex:page >
    <script>
    function f1(uid,pwd){
        var u=document.getElementByid(uid).value;
        var p=document.getElementByid(pwd).value;
        if(u==""){
            alert(' Please enter User name');
            document.getelementbyid(uid).focus();
        }
        else{
            if(u.length<3)
                alert('Please Enter username minimum 3 Characters');
        }
        if(p==""){
            alert('Please Enter Password');
            document.getelementbyid(pwd).focus();
        }
    }
    function f2(uid,pwd){
        document.getelementbyid(uid).value="";
        document.getelementbyid(pwd).value="";
    }
    </script>
    
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection title=" Entry Section">
                <apex:outputText value="Enter User Name"></apex:outputText>
                <apex:inputText id="uid"/>
                <apex:outputText value="Enter Password"></apex:outputText>
                <apex:inputText id="pwd"/>
                
                <apex:commandButton value="Submit" onclick="f1('{!$component.uid}','{!$component.pwd}')"/>
                <apex:commandButton value="CLear" onclick="f2('{!$component.uid}','{!$component.pwd}'"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Set the owner of a contact to the account owner under these conditions:
1-When a contact is created and account is set
2-When the account on a contact is updated
3-When the owner of an account is updated (whether it's a new account or just an owner change)
I created the flow in process builder for condition 3 but can someone  help me for condition 1 and 2. Please paste the flow for 1 & 2 or could we achieve all in 1 process?
Hey guys!

I was hoping to build a web form and upon submission it would automatically create an account, contact and opportunity.  The tough part is that I would want the code to search my SFDC org to validate that it wasn't creating a duplicate account.  If it found an existing account I would want it to associate the contact to the found account instead of creating a duplicate.  Any thoughts on how I could do this via code or would buying a package be the better route?

Thanks!

​Nick
Hi All 

can any one help in writter a trigger,

when parent is deleted the related child records should be deleted.

Thanks in advance.
I want to populate fields on the newly created Opportunity record when a Lead is converted. This can easily be done with field mapping on the Lead object if both the Lead and Opportunity fields are custom fields, but I want to map a custom Lead field to the standard "Amount" field on the Opportunity. Yes, I could recreate a new custom "Amount" field, but that's not the best way.

No matter how I try and create my button logic, it's not taking the fields off the Lead object and populating the standard fields on the new Opportunity. Am I trying to do something not supported by Salesforce, as in prepopulating fields on a 'new' record that is being created by Lead Conversion?
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 want to add success message in code. when i will create a visit. after creating visit success msg should be displayed.

Here I am  Posting my code:

Controller:


public with sharing class MyCompController3

public  id tid{get;set;}
public String str;
public String city{get;set;}
    public MyCompController3(ApexPages.StandardController controller)
     {
 
     }
    
    public pagereference dosome(){
    
wrapAccountList = new List<wrapAccount>();
for(Account a: [select Id, RecordType.Name, Name, City__c from Account where City__c =:city])
{
wrapAccountList.add(new wrapAccount(a));
system.debug('*****************wrapAccountList******************'+wrapAccountList);
}

    return null;
    }

public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('--None--','--None--'));
            options.add(new SelectOption('Ahmednagar','Ahmednagar'));
            options.add(new SelectOption('Akola','Akola'));
            options.add(new SelectOption('Amravati','Amravati'));
            options.add(new SelectOption('Aurangabad','Aurangabad'));
            options.add(new SelectOption('Bhiwandi','Bhiwandi'));
            options.add(new SelectOption('Chandrapur','Chandrapur'));
            options.add(new SelectOption('Chinchwad','Chinchwad'));
            options.add(new SelectOption('Dhule','Dhule'));
            options.add(new SelectOption('Dombivali','Dombivali'));
            options.add(new SelectOption('Jalgaon','Jalgaon'));
            options.add(new SelectOption('Kalyan','Kalyan'));
            options.add(new SelectOption('Kolhapur','Kolhapur'));
            options.add(new SelectOption('Latur','Latur'));
            options.add(new SelectOption('Malegaon','Malegaon'));
            options.add(new SelectOption('Mumbai','Mumbai'));
            options.add(new SelectOption('Nagpur','Nagpur'));
            options.add(new SelectOption('Nanded','Nanded'));
            options.add(new SelectOption('Nashik','Nashik'));
            options.add(new SelectOption('Navi Mumbai','Navi Mumbai'));
            options.add(new SelectOption('Parbhani','Parbhani'));
            options.add(new SelectOption('Pimpri','Pimpri'));
            options.add(new SelectOption('Pune','Pune'));
            options.add(new SelectOption('Sangli','Sangli'));
            options.add(new SelectOption('Satara','Satara'));
            options.add(new SelectOption('Solapur','Solapur'));
            options.add(new SelectOption('Thane','Thane'));
            options.add(new SelectOption('Vasai','Vasai'));
            options.add(new SelectOption('Virar','Virar'));

            return options;
        }


public List<wrapAccount> wrapAccountList {get; set;}
public List<Account> selectedAccount{get;set;}

private List<Id> accountids=new list<Id>();
public List<Account> acc;

public PageReference processSelected()
{
    selectedAccount = new List<Account>();

    for(wrapAccount wrapAccountObj : wrapAccountList)
    {
    if(wrapAccountObj.selected == true)
    {
        selectedAccount.add(wrapAccountObj.acc);
        //accWrap.acc.Name
        system.debug('*****************!!!!!!!!!wrapAccountList******************'+selectedAccount);

    }
    }
             PageReference pageRef = new PageReference('/apex/Visitplan');
             return pageRef;
            
}

public list<Account> srecs;
public list<Account> getSrecs()
{


 
 srecs= [select Id, Name, RecordType.Name, City__c from Account];
 system.debug('*****************!!!!!!!!!srecssrecssrecssrecs******************'+srecs);
 tid = ApexPages.currentPage().getParameters().get('id');
 system.debug('*****************!!!!!!!!!$$$$$$$$$$$$$$$$$$$$$$$$$******************'+tid);

        return selectedAccount;
}
public PageReference CreateRec()
{
for(Account  acr :selectedAccount)
{
Planned_Visit__c pv =new Planned_Visit__c();
pv.Daily_Visit_Plan__c= tid;
pv.Name__c=acr.id;
insert pv;
}
             return null;
}

public class wrapAccount {
public Account acc {get; set;}
public Boolean selected {get; set;}

public wrapAccount(Account a)
 {
acc = a;
selected = false;
}
}
}



VF page 1:

<apex:page standardController="Daily_Visit_Plan__c" extensions="MyCompController3" standardStylesheets="false" sidebar="false">

<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID)
{
var inputCheckBox = document.getElementsByTagName("input"); for(var i=0; i<inputCheckBox.length; i++)
{
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1)
{
inputCheckBox[i].checked = obj.checked;
} } }
</script>

<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Show" action="{!dosome}" reRender="table"/>
<apex:commandButton value="Show Selected" action="{!processSelected}" />
</apex:pageBlockButtons>

<apex:actionRegion >
<apex:selectList value="{!city}" size="1">
<apex:selectOptions value="{!items}"/>
<!--<apex:actionSupport event="onchange" reRender="table" action="{!dosome}" />-->
</apex:selectList>
</apex:actionRegion>
        

<apex:pageblockSection title="All Doctors And Chemists" collapsible="false" columns="1">
<apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" title="All Doctors And Chemists" id="table">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!accWrap.acc.Name}" />
<apex:column value="{!accWrap.acc.City__c}" />
<apex:column value="{!accWrap.acc.RecordType.Name}" />
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

<!--<apex:page standardController="Daily_Visit_Plan__c" extensions="MyCompController" standardStylesheets="false" sidebar="false">

<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>

<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Create Visit" action="{!processSelected}" />
</apex:pageBlockButtons>

<apex:pageblockSection title="All Contacts" collapsible="false" columns="1">
<apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" title="All Doctors And Chemists">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!accWrap.acc.Name}" />

</apex:pageBlockTable>

</apex:pageblockSection>

</apex:pageBlock>
</apex:form>

</apex:page>-->


VF page 2:



<apex:page standardController="Daily_Visit_Plan__c" extensions="MyCompController3" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Displaying selected list of Doctors And Chemist.." collapsible="false">
<apex:pageBlockTable value="{!srecs}" var="item" >
<!--<apex:column value="{!item.id}" />-->
<apex:column value="{!item.name}" />
<apex:column value="{!item.City__c}" />
<apex:column value="{!item.RecordType.Name}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Create Visit" action="{!CreateRec}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Hi,

Thanks in advance,
Am new to apex and visualforce,kindly helpme in the below requirement,
I need to create a custom button on account object and on clicking on it should lead to a visualforce page that contain some of the account and related oppurtunities of the account.kinldy help me out by providing a sample code.

 
Hi, 

   Is there a way to prepare a report in salesforce with gives notes and attachement for user to download. 

Thanks
 

Help me to code it on APEX, the records should be visible to the user if the current user is the CreatedBy.

public class MyFilesSharingHandler {
	public void shareRecord(List<CustomObject__c> scope) {
		if (Trigger.isInsert) {
			
			List<CustomObject__Share> shareLst = new List<CustomObject__Share>();
			for (CustomObject__c c : scope) {
				CustomObject__Share share = new CustomObject__Share();
				share.AccessLevel = 'Read';
				share.ParentId = c.Id;
				share.UserOrGroupId = c.CreatedById;
				shareLst.add(share);
			}
			if (!shareLst.isEmpty()) {
				insert shareLst;
			}
		}
	}
}
Hi,

Im having alot of difficulty with this some Apex Code

Im trying to Query Opportunities that are Opp Enquiry Source contains referrals and the event on it is a Sat On Appointment. So i can get a count of them in visualforce.

I know how to display counts in visualforce, I know how to query singular objects for these results but because of the information is on an event and some is on an opportunity I have come to a sticking point.

I thought i might have been able to do this with I was previously advised to do it via this
What.Opp_Enquiry_Source LIKe :IsRef
However this doesnt work and comes up with 

No such column 'Opp_Enquiry_Source__c' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. Is this because of how the What field works on events. That field defiantly exists ive used it previously but its not working

I thought maybe this the following would work 
return [SELECT Count()
            FROM Opportunity o,o.Event e
WHERE o.Opp_Enquiry_Source__c LIKe :IsRef AND e.Sat_On__c = TRUE
Ive tried this both ways so Event e, e.Opportunity o and Opportunity o,o.Event e

I get this as error 

Didn't understand relationship 'e.Opportunity' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Thank you in advance


 
Hi All,
I have a vf page which have two radio button Yes or No. I want selected value in constructor after clicking on submit buton.
here is code.
<apex:page controller="CCO_ScheduleACallController">
<apex:form >
<apex:pageBlock >
<apex:outputLabel style="Bold">Are you able to launch your software or service?</apex:outputLabel>
<apex:selectRadio value="{!radiovalue}">
          <apex:selectOption itemLabel="Yes" itemValue="1"></apex:selectOption>
          <apex:selectOption itemLabel="No" itemValue="2"></apex:selectOption>
      </apex:selectRadio>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!Submit}" value="Submit"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

Since in the exisitng contrroler most of the logic is implemented in constructor. And now i have to add condition
IF(selected value=='Yes')
{
//code
}
else
{
// code
}

We have a visualforce page and apex to handle configuration of our line items on an opportunity.  How do we restrict updating of the line item fields to only allow update of these records by code?   We don't want the users to update these fields manually.  

We can't change the CRUD permissions to read only because they won't be able to update via the code. 

Can this be accomplished with validation rules or triggers?

Hello. I have a custom object contractor__c child object under opportunity. If a contractor__c is created, I need to make sure one and only one contractor__c is marked as primary for the opportunity. I tried an Apex trigger like this but it's not working. If I set the first contractor as primary, it will also set the second contractor as primary. And if I turn the primary flag off for the first contractor, it does not turn on the primary flag for the second contractor. Any help is appreciated.
 
trigger VerifyOnlyOnePrimaryContractor on Contractor__c (before insert, before update) {
    
    for(Contractor__c c: trigger.new){
        string O = c.Opportunity__c;
        string thisContractor = c.ID;
        //if this contractor is marked primary, make all the others for the same opportunity not primary
        if(c.Primary__c){
            List<contractor__c> cList = [Select id from Contractor__c where Opportunity__c = :O and id <> :thisContractor];
            
            for(contractor__c con : cList){
                con.Primary__c = FALSE;
            }
            update cList;
        }
        
        else{
            //if no contractors are marked as primary, set one of them as primary
            string primary = 'no';
            List<contractor__c> cList1 = [Select id,primary__c from Contractor__c where Opportunity__c = :O];
            if(cList1.size() == 0){
                c.Primary__c = TRUE;
            }
            else
            {
                for(contractor__c con1 : cList1){
                    if(con1.Primary__c){
                        primary = 'yes';
                    }
                }
                if(primary == 'no'){
                    
                    c.Primary__c = TRUE;
                }
            }
        }
        
    }                                                                                                                                                                                                       
}

 
There is two object: Fund and opportunity. and opportunity object has lookup of Fund. I've devloped one trigger that sum up the total amount from all the relative opportunity and set that amount in custom field of fund object. now problem in my code is that whenever I try to create bulk opportunity using CSV file that contain data for multiple fund at that time it sum up the total of all fund and set that only in first record fund ID. I need solution using Map.
Thannk you.

Trigger:
trigger newLeadTrigger on Opportunity (after insert , after update, after delete , after undelete) {
    
    if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate || trigger.isUndelete)){
           OpportunityCustomRollup.CountRollup(Trigger.new);
    }
    
    if(Trigger.isDelete)
    {
        OpportunityCustomRollup.CountRollup(Trigger.old);
    }
}


Controller class:

public class OpportunityCustomRollup {
   
    public static void CountRollup(List<Opportunity> lstOpportunity){
        
        set<id> oppIds = new set<id>();
        map<string, integer> classroomIDToDeskCountMap = new map<string, integer>();
        id objrecordtypeid = [SELECT Id FROM RecordType WHERE DeveloperName ='Fund_Raising'].Id;
        double amount = 0;
        
        try {
                for (Opportunity objOpportunity : lstOpportunity){
                    oppIds.add(objOpportunity.Fund__c);
                }
            
                Fund__c objfund = [SELECT Id, Total_opportunity_amount__c  FROM Fund__c WHERE Id = :oppIds];
                List<Opportunity> list_Opportunity = [SELECT Id, Amount FROM Opportunity WHERE Fund__c = :objfund.Id and StageName = 'Closed Won' and RecordTypeId =: objrecordtypeid];
            
            
                 for(Opportunity AmountOpportunity : list_Opportunity) {
                        amount += AmountOpportunity.amount; 
                 }
            
            
                  objfund.Total_opportunity_amount__c = amount;
                  update objfund;   
            } 
       
        
        catch (Exception e) {
                System.debug(e);
            }
        
    }

}
  
Hi All,

I have a Comments field of Type LongTextArea(Size 256). when i use this field in reports i am getting 253 characters and dots(..) . I am not even getting 254 characters. I just want to display full text from comments field. Any body can help me to solve this problem.
trigger DedupeReminder on Account (after update) {
    for (Account acc: Trigger.New){
        Case c      = New Case();
        c.subject   ='Dedupe this Account';
        c.OwnerId   = '0057F000000tnLj';
        c.AccountId = acc.Id;
        insert c;
    }
}
I am unable to find standard quote template. How to enable/create it?

Thank you.
Hi all, 

Need to capture  user/jobs details who updated case  in both before update (Before update record) , after update(who updated ) ?
need to store  last 30 days records modified user details and modified 10 field values future reference. 

can you please assist me with trigger code. 

 
i'm new to Trigger. i want to write trigger on Opportnuity . 
Opportunity Standard field :CloseDate
Custom Field :Status(Status_c) (picklist)

Custom Object :Customer(Customer__c)
custom field : Contract End Date(Contract_End_Date)

when Opportunity status field is updated to Accepted, then customer  contract end date field should be updated to close date . there is master detail relationship. i have tried to code.
trigger ContractDate on Opportunity ( after update) {
		List <ID> opps=New List<ID>();
    		
    for(Opportunity o:Trigger.new){
        if(o.Status__c=='Approved'){
            opps.add(o.Id);
           
        }
    }
    
    Customer__c customerList=[SELECT Id,Contract_End_Date__c FROM Customer__c WHERE id in:opps];
	
    
    for(Customer__c cst:customerList){
       customerList.Contract_End_Date__c=Opps.CloseDate;
         update cst;
    }
   

}

Hi,

I'm looking into creating a process in which Salesforce will update the parent record if a field on the child has the value 'Rejected'.

So we have a parent object - Offer and child - Offer SIte.
Then if the field Status__c on Offer Site = 'Rejected', I want to apply the same value to a field called Status on Offer automatically once the field on Offer site is updated.

Does anyone know how to do this?
I'm not too sure on how I can write this into trigger as my experience with triggers is basic

Any help is much appreciated.
Thanks.

Hello,

I have a checkbox on Account object "CustomCheck__c"

In the quote, i have a custom button
User-added image
window.location.href='/apex/QUOTES__Quote_Get?&id={!Quote.Id}&retURL=//{!Quote.Id}&cancelURL={!Quote.Id}';

I want to execute this URL only when the checkbox on Account is unticked else display an error message 

How can i acheive it ?

thanks for suggestions
  • May 05, 2017
  • Like
  • 0
public class  FileController {        
    public Document doc {get;set;}  
    public PageReference getFile() {        
        String fileId = System.currentPageReference().getParameters().get('id');        
            if(fileId != null) {            
                doc = [SELECT Id, Name, Description, ContentType, Type, Url, BodyLength, Body               
                       FROM Document WHERE Id = :fileId];   
            }       return null;                
    }                        
}