• Chinnu Chinnu
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 5
    Replies
trigger OpportunityProduct on OpportunityLineItem (before insert,after insert, after update,after delete,after undelete) {
    //Setup the array to hold the Id to Iterate through
    Set<Id> CurrentOppId = new Set<Id>();
    List<string> prodName = new List<string>();
    Map<Id,Id> OppLineItemMap = new Map<Id,Id>();
    
    for (OpportunityLineItem OppLnItem : Trigger.isdelete?trigger.old:trigger.new){
        CurrentOppId.add(OppLnItem.OpportunityId);
        prodName.add(OppLnItem.Product2.name);
        OppLineItemMap.put(OppLnItem.opportunityId,OppLnItem.product2id);
    }
    
    if(trigger.isbefore){
        List<Opportunity> oppLst = [Select id,(select id,product2id,OpportunityId from opportunitylineitems) from opportunity where id=:CurrentOppId];
        for(opportunityLineitem opplit : trigger.new){
            for(opportunity oppt : oppLst){
                for(opportunityLineItem oppli : oppt.opportunitylineitems){
                    if(oppli.Product2Id == OppLineItemMap.get(oppli.OpportunityId)){
                        opplit.adderror('You Cant add the same OpportunityLineItem again');
                    }
                }
            }
        }
    }   
    
    // Create List of One Opportunity Id to Update
    List<Opportunity> OppId = [Select Id from Opportunity where Id in: CurrentOppId];
    
    // Create List of Opportunity Products to iterate through later
    List<OpportunityLineItem> relatedOLIs =
        [Select Id, OpportunityId, PricebookEntry.Product2.name from OpportunityLineItem 
         where OpportunityId in: CurrentOppId];
    
    List<Opportunity> Opplist = New List<Opportunity> ();
    //Iterate through the Opportunity to Update
    for (Opportunity opp2 : OppId){
        opp2.Product_Code_Selected__c = '';
        
        //Iterate through the line items to add PricebookEntryID data to the Opportunity
        for (OpportunityLineItem oli2 : relatedOLIs){
            opp2.Product_Code_Selected__c +=  oli2.PricebookEntry.Product2.name + '; ';                        
        }
        Opplist.add(opp2);
    }
    update Opplist;  
}
Hey, This is my code..
VF page:
<apex:page controller="ContactsVisualforceController" standardStylesheets="false">
    <apex:form>
    <apex:pageBlock title="Contacts List">
   
             
        <apex:repeat value="{!displayAccounts}" var="acc">
           <dl>
                <dt>Account Name:</dt>
                <dd><apex:outputText value="{!acc.Name}"/></dd> 
            </dl>
            
            <dl><dt>Contact Names:</dt></dl>

            <apex:pageblocktable value="{!acc.Contacts}" var="cont">
                
                <apex:column value="{!cont.firstname}"/>
                <apex:column value="{!cont.lastname}"/>

         </apex:pageblocktable>
       </apex:repeat>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class ContactsVisualforceController {
    public list<Account> displayAccounts {get; set;}
    public ContactsVisualforceController(){
        displayAccounts = [select id,name,(select id,name,firstname,lastname from Contacts) from Account];
    }
}


This is working fine ok.. But now I want to display as Block means

AccountName1 here          All related Contacts For that AccountName1 should display here
AccountName2 here          All related Contacts For that AccountName2 should display here
AccountName3 here          All related Contacts For that AccountName3 should display here

like this I want to display 10 records in one page and another 10 records on another page so pagination we have to use..
So I want how can we do that can anyone please tell me..
For example: you will have to create a field in opportunity (Added products - text field) should show product1; product2; product3;

trigger updateAssessmentValue on Assessment__c(after insert, after update) {
  Map<ID, Building__c> parentBuild = new Map<ID, Building__c>(); 
  List<Id> listIds = new List<Id>();

  for (Assessment__c childObj : Trigger.new){
    listIds.add(childObj.Building__c);
  }

  
  parentBuild = new Map<Id, Building__c>([SELECT id, Recent_Assessment_Date__c ,Recent_Assessment_Value__c ,(SELECT ID, Assessment_Value__c,Assessment_Date__c FROM Assessments__r) FROM Building__c WHERE ID IN :listIds]);

  for (Assessment__c assess : Trigger.new){
     Building__c myBuild = parentBuild.get(assess.Building__c);
     myBuild.Recent_Assessment_Date__c = assess.Assessment_Date__c ;
     myBuild.Recent_Assessment_Value__c = assess.Assessment_Value__c;
  }

  update parentBuild.values();
}
Hey, This is my code..
VF page:
<apex:page controller="ContactsVisualforceController" standardStylesheets="false">
    <apex:form>
    <apex:pageBlock title="Contacts List">
   
             
        <apex:repeat value="{!displayAccounts}" var="acc">
           <dl>
                <dt>Account Name:</dt>
                <dd><apex:outputText value="{!acc.Name}"/></dd> 
            </dl>
            
            <dl><dt>Contact Names:</dt></dl>

            <apex:pageblocktable value="{!acc.Contacts}" var="cont">
                
                <apex:column value="{!cont.firstname}"/>
                <apex:column value="{!cont.lastname}"/>

         </apex:pageblocktable>
       </apex:repeat>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class ContactsVisualforceController {
    public list<Account> displayAccounts {get; set;}
    public ContactsVisualforceController(){
        displayAccounts = [select id,name,(select id,name,firstname,lastname from Contacts) from Account];
    }
}


This is working fine ok.. But now I want to display as Block means

AccountName1 here          All related Contacts For that AccountName1 should display here
AccountName2 here          All related Contacts For that AccountName2 should display here
AccountName3 here          All related Contacts For that AccountName3 should display here

like this I want to display 10 records in one page and another 10 records on another page so pagination we have to use..
So I want how can we do that can anyone please tell me..
Account IT = new Account();
String integrationtransactionId= '0016F00001y5mQW';
List<String> fields = new List<String>(Account.SObjectType.getDescribe().fields.getMap().keySet());
String soql='';
soql=soql+' select ';
soql=soql+String.join(fields, ',');
System.debug('checking'+soql);
soql=soql+' from Account where id=:integrationtransactionid';
System.debug('soqq'+soql);
IT=database.query(soql);
System.debug('itt'+IT);
String ack=IT.Request__c;  
System.debug('acksss--'+ack);

 
  • September 20, 2019
  • Like
  • 1