• Sridhar Venkateswaralu 8
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I was having one custom button with JS code as below:
{!requireScript("/soap/ajax/30.0/connection.js")}
{!requireScript("/soap/ajax/30.0/apex.js")}

var opp = new sforce.SObject("Opportunity");
opp.id = "{!Opportunity.Id}";

try {

opp.isStatus = true;

var optresult = sforce.connection.update([opp]);
if(optresult[0].success=='false') {
alert(optresult[0].errors.message);
} else {

sforce.apex.execute('populateOpportunity', 'automatePopulatingOpp', {optyId:'{!Opportunity.Id}', action:'Default'});

alert('{!$Label.SuccessMsg}');
}
} catch(err) {
alert(err.message);
}
document.location = '/{!Opportunity.Id}';

I'm new to vf page implementation. I need to replace this JS with Vf page. I've written below vf page and custom controller.

VF Page
<apex:page standardController="Opportunity"  showHeader="false" extensions="oppController" >   
    <head>
        <style type='text/css'>
            .popupBackground{
            left: 20%;
            color:red;
            position: fixed;
            width: 450px;
            height: 100px;
            margin-left: -200px;
            top: 50px;
            }
            .popupBackground .close{
            position: absolute;
            background:#008CBA;
            color: white;
            bottom: 0;
            right: 10px;
            font-size: 10px;
            text-decoration: none;
            width:50px;
            }
        </style>
    </head>
    
    <apex:form rendered="{!showSuccessMsg}" id="opp">
        <apex:pageMessages id="errmsg"></apex:pageMessages> 
        <body onload="init();">
            <apex:outputPanel styleClass="popupBackground"  >
                <center>
                    <apex:outputText value="{!$Label.SuccessMsg}" escape="false"/>
                    <apex:commandButton value="OK" styleClass="close" onclick="parent.window.close();"/>
                </center>
            </apex:outputPanel>
        </body>
    </apex:form> 
</apex:page>

Custom Controller
public class oppController {
    public Id oppId;
    public Boolean showSuccessMsg{get;set;}
    public Boolean showErrorMsg{get;set;}
    
    public opptController(){
        showSuccessMsg = true;
        showErrorMsg = false;
        
        if(oppId != NULL){
            Opportunity opp = new Opportunity(Id = oppId);
            opp.isStatus = true;
            try{
                update opp;
                populateOpportunity.automatePopulatingOpp(oppId,'Default');
                showSuccessMsg = true;
                showErrorMsg = false;
                Error.LogSuccess(Label.SuccessMsg);
            }catch(Exception e){
                showSuccessMsg = false;
                showErrorMsg = true;
                Error.LogException(e);
            }
            showSuccessMsg = true;
            showErrorMsg = false;
            Error.LogSuccess(Label.SuccessMsg);
        }        
    }
}

Can anyone please help me out to correct this?
  • March 31, 2020
  • Like
  • 0

When am passing LinkedEntityId with any hardcoded incident id, then it is fetching ContentDocumentId and working

But  when passing any list / Id variable LinkedEntityId not fetches  ContentDocumentId .

 SELECT ContentDocumentId,LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId =: InciId / 

SELECT ContentDocumentId,LinkedEntityId FROM ContentDocumentLink 
                           WHERE LinkedEntityId in:incidentIDList (List where inc id's are stored)